How do I run a substitution only within the exact columns of a visual selection, not the whole line?
:'<,'>s/\%Vpattern/replacement/g
When you press : after making a visual selection, Vim inserts ' to restrict the substitution to the selected lines.
category:
visual-mode
tags:
#visual-mode
#search
#editing
#ex-commands
#normal-mode
How do I reflow and hard-wrap a paragraph or selected lines to a fixed width in Vim?
Pressing gq on a visual selection reformats the selected lines to hard-wrap at textwidth columns.
category:
visual-mode
tags:
#visual-mode
#editing
#formatting
How do I adjust the width of a visual block selection without restarting it?
In visual block mode (), pressing O (uppercase) moves your cursor to the other end of the current line — letting you expand or contract the block's horizontal
category:
visual-mode
tags:
#visual-mode
#visual-block
#selection
#editing
How do I reindent a block of code using a visual selection?
After making a visual selection, pressing = applies Vim's auto-indent to every selected line at once.
category:
visual-mode
tags:
#visual-mode
#indentation
#editing
#formatting
How do I run a normal mode command on every line in a visual selection?
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
#normal-mode
How do I replace a visual selection with yanked text in Vim?
In visual mode, pressing p replaces the selected text with the contents of the default register.
category:
visual-mode
tags:
#visual-mode
#editing
#registers
#normal-mode
How do I paste over a visual selection without losing my yanked text?
When you paste over a visual selection using p (lowercase), Vim replaces the selection with your register contents — but the replaced text overwrites your unn
category:
visual-mode
tags:
#visual-mode
#registers
#paste
#editing
How do I move the cursor to the other end of a visual selection without restarting it?
In visual mode, pressing o swaps the cursor between the two ends of the selection (the anchor and the free end).
category:
visual-mode
tags:
#visual-mode
#navigation
#editing
How do I switch between visual mode and select mode in Vim?
Vim has a lesser-known select mode that behaves like selection in typical GUI editors: any typed character replaces the selection.
category:
visual-mode
tags:
#visual-mode
#select-mode
#editing
#normal-mode
How do I change the case of a specific column of text using visual block mode?
Visual block mode lets you select rectangular regions of text, which means you can target a specific column and apply case changes only to that area.
category:
visual-mode
tags:
#visual-mode
#editing
#text-objects
#formatting
How do I turn a visual selection of lines into a numbered list?
:s/^/\=line('.') - line("'<") + 1 . '. '/
When you need to quickly number a set of lines — such as TODO items, steps, or bullet points — you can use a visual selection combined with a substitution e
category:
visual-mode
tags:
#visual-mode
#editing
#ex-commands
#formatting
#substitute
How do I move the cursor to the other end of a visual selection to adjust it?
When you start a visual selection, the cursor is at one end and the anchor is at the other.
category:
visual-mode
tags:
#visual-mode
#navigation
#editing
#motions
How do I align columns of text into a neatly formatted table in Vim?
When working with data that has uneven spacing — such as variable assignments, CSV-like data, or configuration entries — you can select the lines and pipe t
category:
visual-mode
tags:
#visual-mode
#editing
#formatting
#external-command
#alignment
How do I switch between character, line, and block visual selection without reselecting?
v / V / <C-v> (while in visual mode)
When you are already in visual mode and realize you need a different selection type, you do not have to exit and re-enter.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I reformat a paragraph or visual selection to fit a specific line width?
The gq operator reformats text to fit within your configured textwidth.
category:
visual-mode
tags:
#visual-mode
#formatting
#editing
#text-objects
How do I append text to the end of multiple lines of different lengths?
When you need to append text to the end of several lines that have different lengths, visual block mode with $ is the key.
category:
visual-mode
tags:
#visual-mode
#editing
#block-mode
#insert-mode
How do I append text to the end of multiple lines that have different lengths?
Visual block mode normally selects a fixed-width column, which makes appending tricky when lines have different lengths.
category:
visual-mode
tags:
#visual-mode
#editing
#insert-mode
How do I move the cursor to the other end of a Visual selection in Vim?
When you make a Visual selection in Vim, the cursor sits at one end while the other end is anchored.
category:
visual-mode
tags:
#visual-mode
#editing
#navigation
#motions
How do I progressively expand or contract a visual selection by text objects?
In visual mode, repeating text object motions progressively expands the selection.
category:
visual-mode
tags:
#visual-mode
#text-objects
#selection
#motions
How do I indent lines multiple times without reselecting in visual mode?
Normally, pressing > in visual mode indents the selection but exits visual mode, requiring you to press gv to reselect.
category:
visual-mode
tags:
#visual-mode
#indentation
#mapping
#editing