How do I run a search and replace only within a visually selected region?
:'<,'>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.
category:
visual-mode
tags:
#visual-mode
#search
#editing
How do I visually select a code block enclosed in curly braces including the braces themselves?
The aB text object (around Block) selects everything from the matching { to the closing } — including the braces themselves.
category:
visual-mode
tags:
#visual-mode
#text-objects
#editing
How do I visually select the text of a sentence without selecting surrounding whitespace?
The is (inner sentence) text object selects the sentence the cursor is in — excluding any leading or trailing whitespace that separates sentences.
category:
visual-mode
tags:
#visual-mode
#text-objects
#editing
How do I visually select a double-quoted string including the quotes themselves?
Vim's text objects let you select structured regions of text with two-keystroke shortcuts.
category:
visual-mode
tags:
#visual-mode
#text-objects
#editing
How do I visually select an entire sentence in Vim?
The vas command visually selects the current sentence, including surrounding whitespace.
category:
visual-mode
tags:
#visual-mode
#text-objects
#motions
How do I comment out multiple lines at once in Vim without a plugin?
Vim's Visual Block mode lets you prepend characters (like comment markers) to multiple lines simultaneously.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I convert a visually selected block of text to uppercase or lowercase?
In visual mode, pressing U converts all selected characters to uppercase and u converts them to lowercase.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I move to the opposite corner of a visual block selection?
In visual block mode (), pressing O (uppercase) moves the cursor to the diagonally opposite corner of the rectangular selection.
category:
visual-mode
tags:
#visual-mode
#editing
#navigation
How do you select all lines at the same indentation level?
vii with indent-object plugin
The vim-indent-object plugin provides ii (inner indent) and ai (around indent) text objects.
category:
visual-mode
tags:
#visual
#indent
#select
How do you select from cursor to a mark in visual mode?
Press v for visual mode, then 'a to extend the selection to mark a.
category:
visual-mode
tags:
#visual
#select
#mark
How do you increment a column of numbers in visual mode?
Select numbers with visual block mode , then press to increment all selected numbers by 1.
category:
visual-mode
tags:
#visual
#increment
#numbers
How do you paste over selected text without losing the yanked text?
Use "_dP which deletes the selection into the black hole register and pastes before.
category:
visual-mode
tags:
#visual
#paste
#preserve
How do you select a rectangular column of text?
Press for visual block mode, then use movement keys to select a rectangle.
category:
visual-mode
tags:
#visual
#block
#column
How do you select to end of line for multiple lines in block mode?
In visual block mode, press $ to extend each line's selection to its end, even if lines have different lengths.
category:
visual-mode
tags:
#visual
#block
#end-of-line
How do you surround a visual selection with characters?
With the vim-surround plugin, select text visually and press S) to wrap with parentheses.
category:
visual-mode
tags:
#visual
#surround
#wrap
How do you select from cursor to end of line in visual mode?
Press v to enter character-wise visual mode, then $ to extend selection to the end of the line (excluding the newline).
category:
visual-mode
tags:
#visual
#select
#end-line
How do you select text inside HTML/XML tags?
Press vit to select the inner content of the nearest HTML/XML tag.
category:
visual-mode
tags:
#visual
#select
#tags
How do you add line numbers to visually selected lines?
Select lines visually, then run :'!nl -ba to pipe through the nl command which prepends line numbers to each selected line.
category:
visual-mode
tags:
#visual
#number
#lines
How do you filter a visual selection through an external command?
Select lines, then type ! which auto-expands to :'!.
category:
visual-mode
tags:
#visual
#filter
#command
How do you format (rewrap) a visual selection to textwidth?
Select text with v or V, then press gq to format the selection according to textwidth.
category:
visual-mode
tags:
#visual
#format
#wrap