How do I move the cursor to the other end of a Visual selection in Vim?
o (in Visual mode)
When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored.
o (in Visual mode)
When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored.
v3aw
In visual mode, repeating text object motions progressively expands the selection.
>gv
Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect.
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
:set inccommand=split
Neovim's inccommand option provides real-time visual feedback as you type substitution commands.
<C-v>jjr<C-k>12
Visual block mode combined with the replace command and digraph input lets you replace a column of characters with special Unicode characters.
:'<,'>!awk '{print toupper($0)}'
Vim can pipe any visual selection through external Unix commands and replace the selection with the output.
visual-mode #visual-mode #external-command #awk #text-transformation
:'<,'>retab!
The :retab! command converts between tabs and spaces based on your expandtab setting.
g?
Vim has a built-in ROT13 encoding operator accessible via g?.
visual-mode #visual-mode #encoding #rot13 #text-transformation
:'<,'>!awk '{printf "%-20s %s\n", $1, $2}'
By piping a visual selection through awk with printf formatting, you can align columns to fixed widths.
visual-mode #visual-mode #formatting #alignment #external-command
<C-v>j$A;<Esc>
When lines have varying lengths, a normal visual block selection stops at the shortest line.
<C-v>jjI\=printf('%02d ', line('.')-line("'<")+1)<CR><Esc>
By combining visual block insert with Vim's expression register, you can insert dynamically computed line numbers at the start of each selected line.
visual-mode #visual-mode #block-mode #line-numbers #expression-register
<C-v>jjxp
Visual block mode lets you select, cut, and paste rectangular columns of text.
:set virtualedit=block
By default, Vim's visual block mode () is limited by line length — if some lines are shorter than others, the block selection gets ragged.
<C-v>$
In visual block mode, pressing $ extends the selection to the end of every line, even when lines have different lengths.
g<C-a> in visual mode
When you have multiple lines with the same number and want to turn them into a sequence (1, 2, 3.
gcc / gc{motion}
The vim-commentary plugin by Tim Pope provides a simple, operator-based way to comment and uncomment code.
:'<,'>s/pattern/replacement/g
When you make a visual selection and then type :, Vim automatically inserts ' as the range — the marks for the start and end of the last visual selection.
vaB
The aB text object (around Block) selects everything from the matching { to the closing } — including the braces themselves.
vis
The is (inner sentence) text object selects the sentence the cursor is in — excluding any leading or trailing whitespace that separates sentences.