diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-02-22 20:32:52 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2024-02-23 06:39:03 +0800 |
commit | 20e4001eeedc80b1f2857fcaca81f7a211a09b40 (patch) | |
tree | af478c0dc95acf36eaf48d6be9d71539313fd457 /src/nvim/eval.lua | |
parent | bb15fa035610bb9765ca16900703804a88faa3bb (diff) | |
download | rneovim-20e4001eeedc80b1f2857fcaca81f7a211a09b40.tar.gz rneovim-20e4001eeedc80b1f2857fcaca81f7a211a09b40.tar.bz2 rneovim-20e4001eeedc80b1f2857fcaca81f7a211a09b40.zip |
vim-patch:9.1.0120: hard to get visual region using Vim script
Problem: hard to get visual region using Vim script
Solution: Add getregion() Vim script function
(Shougo Matsushita, Jakub Łuczyński)
closes: vim/vim#13998
closes: vim/vim#11579
https://github.com/vim/vim/commit/3f905ab3c4f66562f4a224bf00f49d98a0b0da91
Cherry-pick changes from patch 9.1.0122, with :echom instead of :echow.
Co-authored-by: Shougo Matsushita <Shougo.Matsu@gmail.com>
Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl>
Diffstat (limited to 'src/nvim/eval.lua')
-rw-r--r-- | src/nvim/eval.lua | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/nvim/eval.lua b/src/nvim/eval.lua index 2630241077..231dd1f9bf 100644 --- a/src/nvim/eval.lua +++ b/src/nvim/eval.lua @@ -4355,6 +4355,49 @@ M.funcs = { returns = 'table', signature = 'getreginfo([{regname}])', }, + getregion = { + args = 3, + base = 1, + desc = [=[ + Returns the list of strings from {pos1} to {pos2} as if it's + selected in visual mode of {type}. + For possible values of {pos1} and {pos2} see |line()|. + {type} is the selection type: + "v" for |charwise| mode + "V" for |linewise| mode + "<CTRL-V>" for |blockwise-visual| mode + You can get the last selection type by |visualmode()|. + If Visual mode is active, use |mode()| to get the Visual mode + (e.g., in a |:vmap|). + This function uses the line and column number from the + specified position. + It is useful to get text starting and ending in different + columns, such as |charwise-visual| selection. + + Note that: + - Order of {pos1} and {pos2} doesn't matter, it will always + return content from the upper left position to the lower + right position. + - If 'virtualedit' is enabled and selection is past the end of + line, resulting lines are filled with blanks. + - If the selection starts or ends in the middle of a multibyte + character, it is not included but its selected part is + substituted with spaces. + - If {pos1} or {pos2} equals "v" (see |line()|) and it is not in + |visual-mode|, an empty list is returned. + - If {pos1}, {pos2} or {type} is an invalid string, an empty + list is returned. + + Examples: > + :xnoremap <CR> + \ <Cmd>echom getregion('v', '.', mode())<CR> + < + ]=], + name = 'getregion', + params = { { 'pos1', 'string' }, { 'pos2', 'string' }, { 'type', 'string' } }, + returns = 'string[]', + signature = 'getregion({pos1}, {pos2}, {type})', + }, getregtype = { args = { 0, 1 }, base = 1, |