From abd380e28d48dd155b1e29cd2453f13b28bf7e08 Mon Sep 17 00:00:00 2001 From: Steven Ward Date: Mon, 5 Jun 2023 22:05:51 -0500 Subject: fix(defaults): visual mode star (*,#) is fragile Problem: Visual mode "*", "#" mappings don't work on text with "/", "\", "?", and newlines. Solution: Get the visual selection and escape it as a search pattern. Add functions vim.get_visual_selection and _search_for_visual_selection. Fix #21676 --- runtime/doc/lua.txt | 19 +++++++++++++++++++ runtime/doc/vim_diff.txt | 5 +++-- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'runtime/doc') diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 77a89a123d..9d3a3dec71 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -1410,6 +1410,25 @@ deprecate({name}, {alternative}, {version}, {plugin}, {backtrace}) Return: ~ Deprecated message, or nil if no message was shown. + *vim.get_visual_selection()* +get_visual_selection({list}, {append_empty}) + Gets the content of the visual selection. + + The result is either a string or, if {list} is `true`, a list of strings. + If not in any |visual-mode|, `nil` is returned. + + Parameters: ~ + • {list} boolean|nil Return a list of strings instead of a + string. See |getreg()|. Defaults to `false`. + • {append_empty} boolean|nil Append an empty string to the result when + in |linewise-visual| mode and {list} is `true`. This + will preserve the trailing newline of the selection + when the result is concatenated with `"\n"`. Defaults + to `false`. + + Return: ~ + string|table + inspect({object}, {options}) *vim.inspect()* Gets a human-readable representation of the given object. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 686905537d..4abecfc321 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -119,10 +119,11 @@ of these in your config by simply removing the mapping, e.g. ":unmap Y". nnoremap nohlsearchdiffupdatenormal! inoremap u inoremap u - xnoremap * y/\V" - xnoremap # y?\V" nnoremap & :&& < +Default mappings composed of Lua code are not listed above. Use ":map" to see +the |map-listing|. + DEFAULT AUTOCOMMANDS *default-autocmds* Default autocommands exist in the following groups. Use ":autocmd! {group}" to -- cgit From f39ca5df232cb6e70b1932b7444840acf42cf87b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Wed, 5 Jul 2023 19:47:43 +0200 Subject: refactor(defaults): use vim.region for visual star (*,#) Problem: The parent commit added a new vim.get_visual_selection() function to improve visual star. But that is redundant with vim.region(). Any current limitations of vim.region() should be fixed instead of adding a new function. Solution: Delete vim.get_visual_selection(). Use vim.region() to get the visual selection. TODO: fails with visual "block" selections. --- runtime/doc/lua.txt | 21 +-------------------- runtime/doc/vim_diff.txt | 17 ++++++++--------- 2 files changed, 9 insertions(+), 29 deletions(-) (limited to 'runtime/doc') diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt index 9d3a3dec71..ca4adbce9c 100644 --- a/runtime/doc/lua.txt +++ b/runtime/doc/lua.txt @@ -1408,26 +1408,7 @@ deprecate({name}, {alternative}, {version}, {plugin}, {backtrace}) • {backtrace} boolean|nil Prints backtrace. Defaults to true. Return: ~ - Deprecated message, or nil if no message was shown. - - *vim.get_visual_selection()* -get_visual_selection({list}, {append_empty}) - Gets the content of the visual selection. - - The result is either a string or, if {list} is `true`, a list of strings. - If not in any |visual-mode|, `nil` is returned. - - Parameters: ~ - • {list} boolean|nil Return a list of strings instead of a - string. See |getreg()|. Defaults to `false`. - • {append_empty} boolean|nil Append an empty string to the result when - in |linewise-visual| mode and {list} is `true`. This - will preserve the trailing newline of the selection - when the result is concatenated with `"\n"`. Defaults - to `false`. - - Return: ~ - string|table + (string|nil) # Deprecated message, or nil if no message was shown. inspect({object}, {options}) *vim.inspect()* Gets a human-readable representation of the given object. diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt index 4abecfc321..6ffd45d013 100644 --- a/runtime/doc/vim_diff.txt +++ b/runtime/doc/vim_diff.txt @@ -114,15 +114,14 @@ DEFAULT MAPPINGS *default-mappings* Nvim creates the following default mappings at |startup|. You can disable any of these in your config by simply removing the mapping, e.g. ":unmap Y". ->vim - nnoremap Y y$ - nnoremap nohlsearchdiffupdatenormal! - inoremap u - inoremap u - nnoremap & :&& -< -Default mappings composed of Lua code are not listed above. Use ":map" to see -the |map-listing|. + +- |Y-default| +- |i_CTRL-U-default| +- |i_CTRL-W-default| +- |CTRL-L-default| +- |&-default| +- |v_#-default| +- |v_star-default| DEFAULT AUTOCOMMANDS *default-autocmds* -- cgit