Neovim Visual Mode & Macros: Bulk Editing Superpowers | Episode 4
Video: Neovim Visual Mode & Macros: Bulk Editing Superpowers | Episode 4 by Taught by Celeste AI - AI Coding Coach
Watch full page →Neovim Visual Mode & Macros: Bulk Editing Superpowers
Unlock powerful bulk editing techniques in Neovim by mastering visual modes and macros. Learn how to select text in character, line, and block modes, perform multi-line edits efficiently, and automate repetitive tasks using macros and registers.
Code
" Example: Visual character mode to delete and paste
v " Enter visual character mode and select text
d " Delete the selection (cuts it to unnamed register)
p " Paste the deleted text after the cursor
" Visual line mode with substitution
V " Enter visual line mode and select lines
:s/old/new/g " Substitute 'old' with 'new' in the selection
" Visual block mode to insert text at start of multiple lines
Ctrl-v " Enter visual block mode and select a column
I " Insert text before each selected line
Hello<Esc> " Type 'Hello' and press Esc to apply insertion on all lines
" Macro recording and playback
qa " Start recording macro into register 'a'
iHello<Esc> " Insert 'Hello' at cursor position
q " Stop recording
@a " Replay macro 'a'
10@a " Replay macro 'a' ten times
" Using named registers
"ay " Yank selection into register 'a'
"ap " Paste from register 'a'
"+y " Yank to system clipboard
"+p " Paste from system clipboard
" View contents of registers and macros
:reg a " Show contents of register 'a'
Key Points
- Neovim has three visual modes: character (v), line (V), and block (Ctrl-v) for flexible selections.
- Visual mode commands like d (delete), y (yank), and :s (substitute) operate on the selected text.
- Visual block mode supports multi-line edits including block insert (I), append (A), and change (c).
- Macros recorded with qa...q automate repetitive edits and can be replayed multiple times with @a and counts like 10@a.
- Named registers store yanked text or macros, accessible via "a, "0, and system clipboard with "+ for efficient text management.