Mercurial > vim
comparison runtime/doc/map.txt @ 26708:f0d7cb510ce3
Update runtime files
Commit: https://github.com/vim/vim/commit/fa3b72348d88343390fbe212cfc230fec1602fc2
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Dec 24 13:18:38 2021 +0000
Update runtime files
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 24 Dec 2021 14:30:04 +0100 |
parents | 3a63b1e4a6f4 |
children | edb7d53fc7e3 |
comparison
equal
deleted
inserted
replaced
26707:d1af15dbf206 | 26708:f0d7cb510ce3 |
---|---|
1 *map.txt* For Vim version 8.2. Last change: 2021 Dec 15 | 1 *map.txt* For Vim version 8.2. Last change: 2021 Dec 20 |
2 | 2 |
3 | 3 |
4 VIM REFERENCE MANUAL by Bram Moolenaar | 4 VIM REFERENCE MANUAL by Bram Moolenaar |
5 | 5 |
6 | 6 |
960 character of the text. | 960 character of the text. |
961 The function is called with one String argument: | 961 The function is called with one String argument: |
962 "line" {motion} was |linewise| | 962 "line" {motion} was |linewise| |
963 "char" {motion} was |characterwise| | 963 "char" {motion} was |characterwise| |
964 "block" {motion} was |blockwise-visual| | 964 "block" {motion} was |blockwise-visual| |
965 Although "block" would rarely appear, since it can | 965 The type can be forced, see |forced-motion|. |
966 only result from Visual mode where "g@" is not useful. | |
967 {not available when compiled without the |+eval| | 966 {not available when compiled without the |+eval| |
968 feature} | 967 feature} |
969 | 968 |
970 Here is an example that counts the number of spaces with <F4>: > | 969 Here is an example that counts the number of spaces with <F4>: > |
971 | 970 |
972 nnoremap <expr> <F4> CountSpaces() | 971 nnoremap <expr> <F4> CountSpaces() |
973 xnoremap <expr> <F4> CountSpaces() | 972 xnoremap <expr> <F4> CountSpaces() |
974 " doubling <F4> works on a line | 973 " doubling <F4> works on a line |
975 nnoremap <expr> <F4><F4> CountSpaces() .. '_' | 974 nnoremap <expr> <F4><F4> CountSpaces() .. '_' |
976 | 975 |
977 function CountSpaces(virtualedit = '', irregular_block = v:false, type = '') abort | 976 function CountSpaces(context = {}, type = '') abort |
978 if a:type == '' | 977 if a:type == '' |
979 let &operatorfunc = function('CountSpaces', [&virtualedit, v:false]) | 978 let context = #{ |
979 \ dot_command: v:false, | |
980 \ extend_block: '', | |
981 \ virtualedit: [&l:virtualedit, &g:virtualedit], | |
982 \ } | |
983 let &operatorfunc = function('CountSpaces', [context]) | |
980 set virtualedit=block | 984 set virtualedit=block |
981 return 'g@' | 985 return 'g@' |
982 endif | 986 endif |
983 | 987 |
984 let cb_save = &clipboard | 988 let save = #{ |
985 let sel_save = &selection | 989 \ clipboard: &clipboard, |
986 let reg_save = getreginfo('"') | 990 \ selection: &selection, |
987 let visual_marks_save = [getpos("'<"), getpos("'>")] | 991 \ virtualedit: [&l:virtualedit, &g:virtualedit], |
992 \ register: getreginfo('"'), | |
993 \ visual_marks: [getpos("'<"), getpos("'>")], | |
994 \ } | |
988 | 995 |
989 try | 996 try |
990 set clipboard= selection=inclusive virtualedit= | 997 set clipboard= selection=inclusive virtualedit= |
991 let commands = #{line: "'[V']", char: "`[v`]", block: "`[\<C-V>`]"}->get(a:type, 'v') | 998 let commands = #{ |
992 if getpos("']")[-1] != 0 || a:irregular_block | 999 \ line: "'[V']", |
993 let commands ..= 'oO$' | 1000 \ char: "`[v`]", |
994 let &operatorfunc = function('CountSpaces', [a:virtualedit, v:true]) | 1001 \ block: "`[\<C-V>`]", |
1002 \ }[a:type] | |
1003 let [_, _, col, off] = getpos("']") | |
1004 if off != 0 | |
1005 let vcol = getline("'[")->strpart(0, col + off)->strdisplaywidth() | |
1006 if vcol >= [line("'["), '$']->virtcol() - 1 | |
1007 let a:context.extend_block = '$' | |
1008 else | |
1009 let a:context.extend_block = vcol .. '|' | |
1010 endif | |
1011 endif | |
1012 if a:context.extend_block != '' | |
1013 let commands ..= 'oO' .. a:context.extend_block | |
995 endif | 1014 endif |
996 let commands ..= 'y' | 1015 let commands ..= 'y' |
997 execute 'silent noautocmd keepjumps normal! ' .. commands | 1016 execute 'silent noautocmd keepjumps normal! ' .. commands |
998 echomsg getreg('"')->count(' ') | 1017 echomsg getreg('"')->count(' ') |
999 finally | 1018 finally |
1000 call setreg('"', reg_save) | 1019 call setreg('"', save.register) |
1001 call setpos("'<", visual_marks_save[0]) | 1020 call setpos("'<", save.visual_marks[0]) |
1002 call setpos("'>", visual_marks_save[1]) | 1021 call setpos("'>", save.visual_marks[1]) |
1003 let &clipboard = cb_save | 1022 let &clipboard = save.clipboard |
1004 let &selection = sel_save | 1023 let &selection = save.selection |
1005 let &virtualedit = a:virtualedit | 1024 let [&l:virtualedit, &g:virtualedit] = get(a:context.dot_command ? save : a:context, 'virtualedit') |
1025 let a:context.dot_command = v:true | |
1006 endtry | 1026 endtry |
1007 endfunction | 1027 endfunction |
1008 | 1028 |
1009 An <expr> mapping is used to be able to fetch any prefixed count and register. | 1029 An <expr> mapping is used to be able to fetch any prefixed count and register. |
1010 This also avoids using a command line, which would trigger CmdlineEnter and | 1030 This also avoids using a command line, which would trigger CmdlineEnter and |