How do I save and restore my entire Vim session including open buffers, windows, and layout?
:mksession saves a snapshot of the current Vim session — all open buffers, window splits, tab pages, cursor positions, and folds — to a file called Session.
category:
buffers-windows
tags:
#buffers-windows
#tabs
#config
#ex-commands
How do I scroll the view horizontally so the cursor sits at the leftmost or rightmost visible column?
When nowrap is set and lines extend beyond the screen width, zs and ze snap the horizontal scroll position so the cursor sits exactly at the left or right edge
category:
navigation
tags:
#navigation
#scrolling
How do I jump to a tag definition in a new split window instead of the current buffer?
Pressing g jumps to the definition of the tag under the cursor — just like — but opens the destination in a new horizontal split window.
category:
buffers-windows
tags:
#navigation
#buffers
#windows
#tags
How do I run a single normal mode command without fully leaving insert mode?
Pressing while in insert mode lets you execute exactly one normal mode command and then automatically returns you to insert mode.
category:
editing
tags:
#insert-mode
#editing
#normal-mode
How do I see a diff of my unsaved changes compared to the version on disk?
The command :w !diff % - pipes the current buffer's contents to an external diff command that compares it against the saved file on disk.
category:
buffers-windows
tags:
#buffers-windows
#ex-commands
#editing
#navigation
How do I paste over a visual selection and automatically save the replaced text to a register?
When you visually select text and press p, Vim replaces the selection with the contents of the default register and saves the replaced text into the unnamed reg
category:
visual-mode
tags:
#visual-mode
#registers
#editing
#paste
How do I run a recorded macro on every line in a range without using a count?
The :normal command executes normal-mode keystrokes on each line in a range — including macro playback.
category:
macros
tags:
#macros
#ex-commands
#normal-mode
#editing
How do I center, right-align, or left-align lines of text using Vim's built-in Ex commands?
Vim includes three built-in Ex commands for text alignment that most users never discover: :center, :right, and :left.
category:
editing
tags:
#editing
#formatting
#ex-commands
#indentation
How do I evaluate a Vimscript expression and use the result as my command-line input?
Pressing e on the command line opens a special prompt that lets you type a Vimscript expression.
category:
command-line
tags:
#command-line
#ex-commands
#vimscript
#insert-mode
How do I complete identifiers using ctags from within insert mode?
Pressing in insert mode opens a completion menu populated from your project's tags file.
category:
editing
tags:
#completion
#insert-mode
#editing
How do I create my own custom ex commands in Vim?
:command lets you define new Ex (colon-prefixed) commands with custom names, optional argument handling, and completion.
category:
command-line
tags:
#command-line
#ex-commands
#config
#normal-mode
How do I use a Vimscript expression as the replacement in a substitute command?
Prefixing the replacement field of :s with \= tells Vim to evaluate the rest as a Vimscript expression and use its result as the replacement string.
category:
editing
tags:
#search
#editing
#substitute
#regex
#ex-commands
How do I move the cursor to the opposite corner of a blockwise visual selection?
O (in blockwise visual mode)
In blockwise Visual mode (), pressing O moves the cursor to the diagonally opposite corner of the rectangle.
category:
visual-mode
tags:
#visual-mode
#editing
#motions
How do I make Vim automatically change the working directory to the file I'm editing?
The autochdir option tells Vim to automatically change the current working directory to the directory of the file in the active window whenever you switch buffe
category:
config
tags:
#config
#navigation
#ex-commands
#buffers
How do I limit a search or substitution to only the text I visually selected?
The \%V atom in a Vim pattern matches only inside the last visual selection.
category:
search
tags:
#search
#visual-mode
#substitute
#regex
#text-objects
How do I create a macro that repeats itself until it hits an error or end of file?
A recursive macro is one that calls itself at the end of its own body.
category:
macros
tags:
#macros
#registers
#normal-mode
How do I run a :g or :s command without overwriting my current search pattern?
Whenever Vim runs a command that involves searching — :g, :s, :v, or even moving the cursor with / — it overwrites the last search register (@/).
category:
search
tags:
#search
#ex-commands
#macros
How do I open a file in a split window and jump directly to the first match of a pattern?
The +{cmd} syntax lets you run an Ex command immediately after a file is opened.
category:
buffers-windows
tags:
#buffers-windows
#navigation
#ex-commands
How do I delete from a visual block column to the end of each selected line?
In visual block mode, pressing C (uppercase) deletes from the leftmost column of the selection to the end of every selected line, then drops you into insert mod
category:
visual-mode
tags:
#visual-mode
#editing
#normal-mode
How do I insert the result of a Vimscript expression as a new line?
The :put ={expr} command evaluates a Vimscript expression and inserts the result as a new line below the cursor.
category:
registers
tags:
#registers
#ex-commands
#insert-mode
#normal-mode