diff options
-rw-r--r-- | runtime/doc/map.txt | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt index 2ecfefca7f..b495b355cf 100644 --- a/runtime/doc/map.txt +++ b/runtime/doc/map.txt @@ -872,28 +872,35 @@ 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(type = '') abort + function CountSpaces(virtualedit = '', irregular_block = v:false, type = '') abort if a:type == '' - set opfunc=CountSpaces + let &operatorfunc = function('CountSpaces', [&virtualedit, v:false]) + set virtualedit=block return 'g@' endif + let cb_save = &clipboard let sel_save = &selection let reg_save = getreginfo('"') - let cb_save = &clipboard let visual_marks_save = [getpos("'<"), getpos("'>")] try - set clipboard= selection=inclusive - let commands = #{line: "'[V']y", char: "`[v`]y", block: "`[\<c-v>`]y"} - silent exe 'noautocmd keepjumps normal! ' .. get(commands, a:type, '') - echom count(getreg('"'), ' ') + 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]) + 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 endtry endfunction |