How do I run a global command only on lines within a visual selection?
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
261 results for "visual mode"
:'<,'>g/pattern/command
How it works The :g (global) command is one of Vim's most powerful features.
J (in visual mode)
In visual mode, pressing J joins all selected lines into a single line with spaces between them.
<C-v>$
In visual block mode, pressing $ extends the selection to the end of every line, even when lines have different lengths.
:'<,'>s/\%Vpattern/replacement/g
Using \%V in a substitute pattern restricts matching to within the visual block area only, rather than the full lines.
: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.
y/\V<C-r>"<CR>
By yanking a visual selection and pasting it into the search prompt with \V (very nomagic), you can search for exact text including special characters.
<C-v>jj$A
Combining visual block mode with $ and A lets you append text at the end of multiple lines, even when the 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.
:'<,'>normal @a
The :'normal @a command executes the macro stored in register a on every line within the current visual selection.
:'<,'>!column -t
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
visual-mode #visual-mode #editing #formatting #external-command #alignment
!sort
Vim can pipe a visual selection through any shell command and replace the selection with the command's output.
visual-mode #visual-mode #ex-commands #external-commands #filtering
<C-n>
The vim-visual-multi plugin (formerly vim-multiple-cursors) brings VS Code-style multiple cursor editing to Vim.
plugins #plugins #visual-multi #editing #multiple-cursors #refactoring
<C-n> to select (vim-visual-multi)
vim-visual-multi provides VS Code-style multiple cursor support for Vim.
:'<,'>norm I//
After making a visual selection, :norm {commands} executes normal-mode keystrokes on every line in the range.
<C-v>selection c
In visual block mode, pressing c changes (replaces) all the text in the selected rectangle.
vi{
The vi{ command visually selects everything inside the nearest pair of curly braces {}, without selecting the braces themselves.
visual-mode #visual-mode #text-objects #editing #normal-mode
<C-v>$A
When you need to append text to the end of several lines that have different lengths, visual block mode with $ is the key.
:'<,'>sort
The :'sort command sorts the currently selected lines in visual mode alphabetically.
g<C-g>
While shows basic file info (filename, line count, position), g provides a much more detailed statistical breakdown of your file or visual selection.
vat
The vat command visually selects the nearest enclosing HTML or XML tag and all of its contents, including the opening and closing tags themselves.
visual-mode #visual-mode #text-objects #editing #normal-mode