How do I apply a macro to every line in a visual selection?
:'<,'>normal @q
The :'normal @q command runs macro q on every line of the visual selection.
261 results for "visual mode"
:'<,'>normal @q
The :'normal @q command runs macro q on every line of the visual selection.
<C-v>jjll"ay
Enter visual block mode with , select the block, then "ay to yank the block into register a.
<C-v>jjg<C-a>
Select a column of identical numbers with , then press g to create an incrementing sequence (1,2,3.
U
In visual mode, pressing U converts all selected characters to uppercase and u converts them to lowercase.
:'<,'>!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.
:'<,'>copy'>
How it works The :copy command (or its abbreviation :t) duplicates lines to a specified destination.
<C-v>j$
In visual block mode, press $ to extend each line's selection to its end, even if lines have different lengths.
viw
How it works The command viw selects the word under the cursor in visual mode.
g?
Vim has a built-in ROT13 encoding operator accessible via g?.
visual-mode #visual-mode #encoding #rot13 #text-transformation
visual select + d, move, P
To swap two pieces of text, delete the first selection, navigate to the second, select it, and paste.
:'<,'>!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
: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
visual-mode #visual-mode #editing #ex-commands #formatting #substitute
<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.
<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
gq (visual mode)
Pressing gq on a visual selection reformats the selected lines to hard-wrap at textwidth columns.
<C-v>jjlU
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.
"ayv
Using named registers with visual mode lets you store multiple independent snippets simultaneously.
<C-v>jj$A;
Visual block mode normally selects a fixed-width column, which makes appending tricky when lines have different lengths.
=
Pressing = in visual mode auto-indents the selected lines according to Vim's built-in indentation rules.
visual-mode #editing #visual-mode #indentation #formatting #productivity