Vim Recall繁體中文

Don't reselect the previous Visual area when executing a mapping or menu in Select mode

gV

Example

Select 0 / 1
one two
three four
Cursor on line 1, column 3 · Character selection

Don'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
Before & after
Before
one two
three four
Cursor on line 1, column 3 · Character selection

Prepared Visual/Select mapping

Definition
:vnoremap <F5> :<C-U>let g:demo=1<CR>gV
demo
0
After
one two
three four
Cursor on line 1, column 1

Prepared 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.