summaryrefslogtreecommitdiffstats
path: root/runtime/doc/map.txt
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2020-09-07 22:18:52 +0200
committerBram Moolenaar <Bram@vim.org>2020-09-07 22:18:52 +0200
commit1c6737b20a5cf71751b180461cea22fc76d8870c (patch)
treeb4fb75497cb2c47f09de1de5bea821af222756ce /runtime/doc/map.txt
parent9c929713b7588f2e44a1533809d2ba0bbd2631be (diff)
Update runtime files.
Diffstat (limited to 'runtime/doc/map.txt')
-rw-r--r--runtime/doc/map.txt69
1 files changed, 37 insertions, 32 deletions
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 83fdbbb825..8900026a1f 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1,4 +1,4 @@
-*map.txt* For Vim version 8.2. Last change: 2020 Aug 30
+*map.txt* For Vim version 8.2. Last change: 2020 Sep 06
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -195,7 +195,7 @@ Note that this works when the <nowait> mapping fully matches and is found
before any partial matches. This works when:
- There is only one matching buffer-local mapping, since these are always
found before global mappings.
-- There is another buffer-local mapping that partly matches, but it is was
+- There is another buffer-local mapping that partly matches, but it is
defined earlier (last defined mapping is found first).
*:map-<silent>* *:map-silent*
@@ -289,15 +289,8 @@ Here is an example that inserts a list number that increases: >
CTRL-L inserts the next number, CTRL-R resets the count. CTRL-R returns an
empty string, so that nothing is inserted.
-Note that there are some tricks to make special keys work and escape CSI bytes
-in the text. The |:map| command also does this, thus you must avoid that it
-is done twice. This does not work: >
- :imap <expr> <F3> "<Char-0x611B>"
-Because the <Char- sequence is escaped for being a |:imap| argument and then
-again for using <expr>. This does work: >
- :imap <expr> <F3> "\u611B"
-Using 0x80 as a single byte before other text does not work, it will be seen
-as a special key.
+Note that using 0x80 as a single byte before other text does not work, it will
+be seen as a special key.
1.3 MAPPING AND MODES *:map-modes*
@@ -881,35 +874,47 @@ g@{motion} Call the function set by the 'operatorfunc' option.
Here is an example that counts the number of spaces with <F4>: >
- nmap <silent> <F4> :set opfunc=CountSpaces<CR>g@
- vmap <silent> <F4> :<C-U>call CountSpaces(visualmode(), 1)<CR>
+ nnoremap <expr> <F4> CountSpaces()
+ xnoremap <expr> <F4> CountSpaces()
+ " doubling <F4> works on a line
+ nnoremap <expr> <F4><F4> CountSpaces() .. '_'
- function! CountSpaces(type, ...)
- let sel_save = &selection
- let &selection = "inclusive"
- let reg_save = @@
-
- if a:0 " Invoked from Visual mode, use gv command.
- silent exe "normal! gvy"
- elseif a:type == 'line'
- silent exe "normal! '[V']y"
- else
- silent exe "normal! `[v`]y"
- endif
-
- echomsg strlen(substitute(@@, '[^ ]', '', 'g'))
+ function CountSpaces(type = '') abort
+ if a:type == ''
+ set opfunc=CountSpaces
+ return 'g@'
+ endif
- let &selection = sel_save
- let @@ = reg_save
+ 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 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
+ endtry
endfunction
+An <expr> mapping is used to be able to fetch any prefixed count and register.
+This also avoids using a command line, which would trigger CmdlineEnter and
+CmdlineLeave autocommands.
+
Note that the 'selection' option is temporarily set to "inclusive" to be able
to yank exactly the right text by using Visual mode from the '[ to the ']
mark.
-Also note that there is a separate mapping for Visual mode. It removes the
-"'<,'>" range that ":" inserts in Visual mode and invokes the function with
-visualmode() and an extra argument.
+Also note that the 'clipboard' option is temporarily emptied to avoid
+clobbering the `"*` or `"+` registers, if its value contains the item `unnamed`
+or `unnamedplus`.
==============================================================================
2. Abbreviations *abbreviations* *Abbreviations*