How do I expand or shrink a visual selection to the next text object boundary?
v + repeated iw/aw/i(/a(/ip/ap
Once you enter visual mode, you can progressively expand your selection by typing increasingly larger text objects.
category:
visual-mode
tags:
#visual-mode
#text-objects
#editing
#selection
#productivity
How do I save a recorded macro permanently so it persists across Vim sessions?
let @a = 'macro_contents'
Recorded macros are stored in registers, which are lost when you quit Vim (unless viminfo saves them).
category:
macros
tags:
#macros
#config
#registers
#vimrc
#productivity
How do I scroll the screen so the current line is at the top?
The zt command repositions the viewport so that the line where your cursor sits moves to the top of the screen, without changing your cursor position within the
category:
navigation
tags:
#navigation
#scrolling
#normal-mode
#viewport
#productivity
How do I scroll two split windows in sync so they move together?
The scrollbind option locks two or more windows together so that scrolling in one window automatically scrolls the others by the same amount.
category:
buffers-windows
tags:
#windows
#navigation
#splits
#diff
#productivity
How do I search and replace text across multiple files in Vim?
:args **/*.py | argdo %s/old/new/gc | update
Vim can perform search-and-replace across multiple files without any plugins by combining the arglist with :argdo.
category:
search
tags:
#search
#substitution
#ex-commands
#productivity
#quickfix
#arglist
How do I select the text I just pasted or changed?
The ` [v] sequence visually selects the exact region of text that was last changed, pasted, or yanked into the buffer.
category:
visual-mode
tags:
#editing
#visual-mode
#marks
#paste
#productivity
How do I switch between buffers without being forced to save first?
By default, Vim refuses to let you switch away from a buffer that has unsaved changes, forcing you to save or discard with :w or :e! before moving on.
category:
config
tags:
#config
#buffers
#vimrc
#productivity
#workflow
How do I execute a single normal mode command without leaving insert mode?
Pressing in insert mode lets you execute one normal mode command and then automatically returns you to insert mode.
category:
editing
tags:
#editing
#insert-mode
#normal-mode
#productivity
How do I see spelling correction suggestions for a misspelled word?
When spell checking is enabled, the z= command opens a numbered list of spelling suggestions for the misspelled word under the cursor.
category:
editing
tags:
#editing
#spell-check
#normal-mode
#productivity
#prose
How do I search for the word under the cursor without whole-word boundaries?
The g command searches forward for the text under the cursor without adding word boundary anchors.
category:
search
tags:
#search
#navigation
#normal-mode
#motions
#productivity
How do I capture the output of a Vim command into a register or buffer?
:redir @a | {cmd} | redir END
The :redir command redirects the output of Ex commands to a register, file, or variable instead of displaying it on the screen.
category:
command-line
tags:
#command-line
#ex-commands
#registers
#productivity
#advanced
How do I repeat the last f, t, F, or T character search on a line?
After using f, t, F, or T to jump to a character on the current line, pressing ; repeats the same search in the same direction, and , repeats it in the opposite
category:
navigation
tags:
#navigation
#motions
#normal-mode
#editing
#productivity
How do I repeat the last Ex command I ran?
The @: command re-executes the most recently run Ex command (any command starting with :).
category:
command-line
tags:
#command-line
#ex-commands
#repeat
#normal-mode
#productivity
How do I make Vim automatically jump to where I last edited when reopening a file?
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
Vim remembers the last cursor position for every file you edit (stored in the viminfo or shada file), but by default it opens files at line 1.
category:
config
tags:
#config
#autocmd
#navigation
#vimrc
#productivity
How do I jump back to where I last inserted text and continue typing?
The gi command moves the cursor to the position where you last exited insert mode and immediately enters insert mode again.
category:
navigation
tags:
#navigation
#insert-mode
#marks
#normal-mode
#productivity
How do I reuse my last search pattern in a substitute command without retyping it?
Leaving the search field empty in a :s command tells Vim to reuse the last search pattern from / or .
category:
search
tags:
#search
#substitution
#ex-commands
#regex
#productivity
How do I run a macro across all open buffers at once?
The :bufdo command executes an Ex command in every open buffer, and when combined with :normal @a, it replays macro a across all of them.
category:
macros
tags:
#macros
#buffers
#ex-commands
#automation
#productivity
How do I save my entire Vim workspace and restore it later?
:mksession / :source Session.vim
Vim's session feature saves a snapshot of your entire workspace — open buffers, window layout, tab pages, current directory, and more — to a file that you c
category:
buffers-windows
tags:
#buffers
#windows
#config
#productivity
#workflow
#session
How do I set Vim options on a per-file basis without changing my vimrc?
A modeline is a special comment embedded in a file that Vim reads to apply file-specific settings automatically.
category:
config
tags:
#config
#editing
#modeline
#formatting
#productivity
How do I move the current line up or down without cutting and pasting?
The :m (move) command relocates lines to a new position in the file without using registers.
category:
editing
tags:
#editing
#ex-commands
#lines
#productivity
#mappings