diff options
author | Bram Moolenaar <Bram@vim.org> | 2021-12-24 13:18:38 +0000 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2021-12-24 13:18:38 +0000 |
commit | fa3b72348d88343390fbe212cfc230fec1602fc2 (patch) | |
tree | c0f27c44f2819613a4288bfc6ebc5c58f421d90d /runtime/doc/map.txt | |
parent | d3f00f54bf955bd01767db3a0af25866bc112ec7 (diff) |
Update runtime files
Diffstat (limited to 'runtime/doc/map.txt')
-rw-r--r-- | runtime/doc/map.txt | 58 |
1 files changed, 39 insertions, 19 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index fc3f42584c..b8806d2cad 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -1,4 +1,4 @@ -*map.txt* For Vim version 8.2. Last change: 2021 Dec 15 +*map.txt* For Vim version 8.2. Last change: 2021 Dec 20 VIM REFERENCE MANUAL by Bram Moolenaar @@ -962,8 +962,7 @@ g@{motion} Call the function set by the 'operatorfunc' option. "line" {motion} was |linewise| "char" {motion} was |characterwise| "block" {motion} was |blockwise-visual| - Although "block" would rarely appear, since it can - only result from Visual mode where "g@" is not useful. + The type can be forced, see |forced-motion|. {not available when compiled without the |+eval| feature} @@ -974,35 +973,56 @@ Here is an example that counts the number of spaces with <F4>: > " doubling <F4> works on a line nnoremap <expr> <F4><F4> CountSpaces() .. '_' - function CountSpaces(virtualedit = '', irregular_block = v:false, type = '') abort + function CountSpaces(context = {}, type = '') abort if a:type == '' - let &operatorfunc = function('CountSpaces', [&virtualedit, v:false]) + let context = #{ + \ dot_command: v:false, + \ extend_block: '', + \ virtualedit: [&l:virtualedit, &g:virtualedit], + \ } + let &operatorfunc = function('CountSpaces', [context]) set virtualedit=block return 'g@' endif - let cb_save = &clipboard - let sel_save = &selection - let reg_save = getreginfo('"') - let visual_marks_save = [getpos("'<"), getpos("'>")] + let save = #{ + \ clipboard: &clipboard, + \ selection: &selection, + \ virtualedit: [&l:virtualedit, &g:virtualedit], + \ register: getreginfo('"'), + \ visual_marks: [getpos("'<"), getpos("'>")], + \ } try set clipboard= selection=inclusive virtualedit= - let commands = #{line: "'[V']", char: "`[v`]", block: "`[\<C-V>`]"}->get(a:type, 'v') - if getpos("']")[-1] != 0 || a:irregular_block - let commands ..= 'oO$' - let &operatorfunc = function('CountSpaces', [a:virtualedit, v:true]) + let commands = #{ + \ line: "'[V']", + \ char: "`[v`]", + \ block: "`[\<C-V>`]", + \ }[a:type] + let [_, _, col, off] = getpos("']") + if off != 0 + let vcol = getline("'[")->strpart(0, col + off)->strdisplaywidth() + if vcol >= [line("'["), '$']->virtcol() - 1 + let a:context.extend_block = '$' + else + let a:context.extend_block = vcol .. '|' + endif + endif + if a:context.extend_block != '' + let commands ..= 'oO' .. a:context.extend_block endif let commands ..= 'y' execute 'silent noautocmd keepjumps normal! ' .. commands echomsg getreg('"')->count(' ') finally - call setreg('"', reg_save) - call setpos("'<", visual_marks_save[0]) - call setpos("'>", visual_marks_save[1]) - let &clipboard = cb_save - let &selection = sel_save - let &virtualedit = a:virtualedit + call setreg('"', save.register) + call setpos("'<", save.visual_marks[0]) + call setpos("'>", save.visual_marks[1]) + let &clipboard = save.clipboard + let &selection = save.selection + let [&l:virtualedit, &g:virtualedit] = get(a:context.dot_command ? save : a:context, 'virtualedit') + let a:context.dot_command = v:true endtry endfunction |