Actually,
<A-K> and <A-S-K> are the same. Instead of "A" you can use "M". If you have
an actual Meta modifier key, please see |:map-meta-keys|.
In the GUI Nvim handles the |ALT| key itself, thus mapping keys with ALT
should always work. But in a terminal Nvim gets a sequence of bytes and has
to figure out whether ALT was pressed. Terminals may use ESC to indicate that
ALT was pressed. If ESC is followed by a {key} within 'ttimeoutlen'
milliseconds, the ESC is interpreted as:
<ALT-{key}>
otherwise it is interpreted as two key presses:
<ESC> {key}
1.11 MAPPING META-KEYS *:map-meta-keys*
Mapping keys with the Meta modifier works very similar to using the Alt key.
What key on your keyboard produces the Meta modifier depends on your keyboard
and configuration.
Note that mapping <M-a> actually is for using the Alt key. That can be
confusing! It cannot be changed, it would not be backwards compatible.
For the Meta modifier the "T" character is used. For example, to map Meta-b
in Insert mode: >
:imap <T-b> terrible
1.12 MAPPING SUPER-KEYS or COMMAND-KEYS *:map-super-keys* *:map-cmd-key*
The Super / Command modifier is available if the terminal or GUI supports it.
The character "D" is used for the Super / Command modifier.
For example, to map Command-b in Insert mode: >
:imap <D-b> barritone
1.13 MAPPING AN OPERATOR *:map-operator*
An operator is used before a {motion} command. To define your own operator
you must create a mapping that first sets the 'operatorfunc' option and then
invoke the |g@| operator. After the user types the {motion} command the
specified function will be called.
*g@* *E774* *E775*
g@{motion} Call the function set by the 'operatorfunc' option.
The '[ mark is positioned at the start of the text
moved over by {motion}, the '] mark on the last
character of the text.
The function is called with one String argument:
"line" {motion} was |linewise|
"char" {motion} was |charwise|
"block" {motion} was |blockwise-visual|
The type can be forced, see |forced-motion|.
Here is an example that counts the number of spaces with <F4>: >
nnoremap <expr> <F4> CountSpaces()
xnoremap <expr> <F4> CountSpaces()
" doubling <F4> works on a line
nnoremap <expr> <F4><F4> CountSpaces() .. '_'
function CountSpaces(context = {}, type = '') abort
if a:type == ''
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 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>`]",
\ }[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('"', 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
An <expr> mapping is used