Don't reselect the previous Visual area when executing a mapping or menu in Select mode
gV
Example
Select 0 / 1Normal 1 / 1one two
three fourCursor on line 1, column 3 · Character selectionone two
three fourCursor on line 1, column 1Don't reselect the previous Visual area when executing a mapping or menu in Select mode.
Prepared Visual/Select mapping
- Definition
:vnoremap <F5> :<C-U>let g:demo=1<CR>gV- demo
0
Run the prepared mapping; gV suppresses reselection and leaves Normal mode at the start of one.
Prepared Visual/Select mapping
- Definition
:vnoremap <F5> :<C-U>let g:demo=1<CR>gV- demo
1- Reselection
Suppressed by final gV
Before & after
one two
three fourCursor on line 1, column 3 · Character selectionPrepared Visual/Select mapping
- Definition
:vnoremap <F5> :<C-U>let g:demo=1<CR>gV- demo
0
one two
three fourCursor on line 1, column 1Prepared Visual/Select mapping
- Definition
:vnoremap <F5> :<C-U>let g:demo=1<CR>gV- demo
1- Reselection
Suppressed by final gV
ILLUSTRATION. Start with one selected in Select mode. The prepared vnoremap applies to Visual and Select modes, enters Ex input with :, and clears its implicit Visual range with Ctrl-u before the harmless let assignment. Its final gV suppresses the Select reselection that otherwise follows this mapping.
Details & Vim help
Don't reselect the previous Visual area when executing a mapping or menu in Select mode. Use in Normal mode. Availability and exact behavior can depend on Vim build features, options, mappings and editor state; the linked help is authoritative.