vim: Select mode mappings switch to visual mode
Vim's "visual" mode allows visual selection of characters, lines, or rectangular blocks, that you can act upon with any of vim's many actions. Vim's "select" mode is a visual selection that is immediately replaced with anything typed, much like all non-modal editors. Despite the different type of interaction a key press might have in those two modes, you can define a keyboard mapping that applies in both modes with vmap
or vnoremap
. That works because vim will automatically switch from select mode into visual mode before running the mapped keys.
For example, say you wanted to map <F7>
to change the selection to 123
. Here are the mappings you could use:
- Select only:
snoremap <F7> 123
- Visual only:
xnoremap <F7> c123<ESC>
- Both modes:
vnoremap <F7> c123<ESC>
(same as visual mode mapping)
Published on: 08 Aug 2024