How do I revert a file to its state from a specific time ago?
:earlier {time} / :later {time}
Vim's :earlier and :later commands let you navigate the undo history by wall-clock time rather than by individual undo steps.
category:
editing
tags:
#editing
#undo-redo
#ex-commands
#advanced
#productivity
How do I center the screen on the cursor line?
The zz command scrolls the window so that the current cursor line appears in the middle of the screen.
category:
navigation
tags:
#navigation
#normal-mode
How do I search for multiple alternative patterns at once in Vim?
Vim's search supports alternation with the \ operator, allowing you to find any one of several patterns in a single search.
category:
search
tags:
#search
#regex
#alternation
#patterns
How do I insert the contents of another file into the current buffer?
The :r filename command reads the contents of filename and inserts them into the current buffer below the cursor line.
category:
command-line
tags:
#ex-commands
#editing
#buffers
How do I insert sequential line numbers using visual block mode?
<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.
category:
visual-mode
tags:
#visual-mode
#block-mode
#line-numbers
#expression-register
How do I run a normal mode command on every line matching a pattern?
The :g/pattern/normal {commands} command executes normal mode keystrokes on every line in the file that matches the given pattern.
category:
command-line
tags:
#ex-commands
#command-line
#editing
#search
How do I prevent a split window from being resized by Vim?
When you have a specific window you want to keep at a fixed size — like a terminal, log viewer, or reference file — winfixheight and winfixwidth prevent Vim
category:
buffers-windows
tags:
#buffers-windows
#windows
#resize
#layout
How do I make a macro run repeatedly until it reaches the end of the file or encounters an error?
A recursive macro is a macro that calls itself at the end of its recording.
category:
macros
tags:
#macros
#editing
#normal-mode
#registers
How do I insert the result of a calculation directly while typing in insert mode?
The expression register (=) in insert mode lets you evaluate any Vimscript expression and insert the result inline.
category:
editing
tags:
#editing
#expression
#insert-mode
#calculator
How do I jump to the global definition of a variable or function in Vim?
How it works Vim provides two built-in commands for jumping to where an identifier is defined, without needing tags or an LSP: gd (lowercase) searches backward
category:
navigation
tags:
#navigation
#normal-mode
#motions
How do I insert the output of a shell command into my buffer?
The :read !{command} syntax runs a shell command and inserts its output below the current line.
category:
editing
tags:
#editing
#shell
#read
#external-command
How do I select to the end of each line in visual block mode?
In visual block mode, pressing $ extends the selection to the end of every line, even when lines have different lengths.
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I navigate back through the tag stack after jumping to definitions?
When you jump to a tag definition with , Vim pushes your location onto a tag stack.
category:
navigation
tags:
#navigation
#tags
#tag-stack
#code-navigation
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 run an interactive git blame inside Vim?
The vim-fugitive plugin by Tim Pope provides a powerful interactive :Git blame that goes far beyond the basic command-line git blame.
category:
plugins
tags:
#plugins
#fugitive
#git
#blame
#history
How do I quickly re-insert the text I just typed without leaving insert mode?
While in insert mode, pressing re-inserts whatever text you typed during your previous insert session.
category:
editing
tags:
#insert-mode
#editing
#registers
#repeat
How do I search for a pattern that spans multiple lines?
Vim's default .
category:
search
tags:
#search
#regex
#patterns
#advanced
#multiline
How do I inspect what key sequences are stored in a macro register?
When a macro behaves unexpectedly, :echo strtrans(@q) reveals exactly what is stored in register q—including invisible control characters—as human-readable
category:
macros
tags:
#macros
#registers
#debugging
How do I jump to the middle of a line in Vim?
The gM command moves the cursor to the horizontal middle of the current line, regardless of how long the line is.
category:
navigation
tags:
#navigation
#motions
#normal-mode
How do I open a file in a new tab in Vim?
Vim's tab pages let you keep separate window layouts open at the same time, each with its own set of splits.
category:
buffers-windows
tags:
#buffers
#tabs
#windows
#ex-commands