How do I reformat a paragraph or motion to fit within the text width without moving my cursor?
The gw operator reformats text to fit within textwidth, just like gq — but with one key difference: gw leaves the cursor in its original position after format
category:
editing
tags:
#editing
#formatting
#text-objects
#normal-mode
How do I run a normal mode command on multiple lines at once?
The :normal Ex command lets you execute any Normal mode keystrokes on a range of lines simultaneously, turning a single-line operation into a multi-line batch e
category:
editing
tags:
#editing
#normal-mode
#ex-commands
#visual-mode
#text-manipulation
How do I detect which register was specified before executing a custom mapping in Vim?
When writing custom mappings or operator functions, v:register gives you the register name that the user prefixed the mapping with.
category:
registers
tags:
#registers
#macros
#normal-mode
#ex-commands
How do I read a single keystroke from the user inside a Vimscript mapping or function?
getchar() blocks and waits for the user to press a key, returning its numeric character code.
category:
macros
tags:
#macros
#vimscript
#normal-mode
#registers
How do I quit Vim without saving using a two-keystroke normal mode shortcut?
ZQ is the discard-and-quit counterpart to ZZ.
category:
editing
tags:
#editing
#normal-mode
#ex-commands
How do I make Vim preserve the cursor column when jumping between lines?
By default, many Vim movement commands — gg, G, Ctrl-d, Ctrl-u, Ctrl-f, Ctrl-b, and others — snap the cursor to the first non-blank character of the destina
category:
config
tags:
#navigation
#config
#motions
#normal-mode
How do I join a specific number of lines at once without pressing J multiple times?
The J command joins the current line with the line below, adding a space between them.
category:
editing
tags:
#editing
#normal-mode
#join
#motions
How do I enable Ctrl-A and Ctrl-X to increment and decrement binary numbers like 0b1010 in Vim?
Vim's and commands increment and decrement numbers under the cursor, but by default they only handle decimal and hexadecimal.
category:
config
tags:
#editing
#config
#increment
#normal-mode
#numbers
How do I show both the absolute line number on the current line and relative numbers on all other lines?
:set number relativenumber
Enabling both number and relativenumber simultaneously activates hybrid line numbering: the current line displays its true absolute line number while every othe
category:
config
tags:
#config
#navigation
#normal-mode
#editing
How do I switch from the active command line into the command-line window to edit the command with full Vim power?
Pressing while you are already typing in the Vim command line (:), search line (/ or ?), or input prompt switches you into the command-line window with the curr
category:
command-line
tags:
#command-line
#ex-commands
#editing
#normal-mode
How do I create a fold that spans the current paragraph in manual fold mode?
Combining the fold-creation operator zf with the ap (around paragraph) text object gives you a quick way to collapse any paragraph into a single fold line.
category:
editing
tags:
#folding
#text-objects
#normal-mode
#editing
How do I execute a motion or command without adding an entry to the jump list?
The :keepjumps modifier lets you run any movement or command without recording a new entry in the jump list.
category:
navigation
tags:
#navigation
#ex-commands
#jump-list
#normal-mode
#vimscript
How do I highlight only the line number of the current line without highlighting the entire line?
:set cursorlineopt=number
When cursorline is enabled, Vim highlights the entire line the cursor is on.
category:
config
tags:
#config
#navigation
#normal-mode
How do I run a command on lines matching a pattern within blocks matching another pattern?
The :global command accepts a range, which lets you scope its search to sections of the file rather than the entire buffer.
category:
command-line
tags:
#ex-commands
#search
#editing
#normal-mode
How do I create a mapping that applies only in visual mode but not in select mode?
:vmap applies to both visual mode and select mode, which can silently break snippet plugins (like UltiSnips, LuaSnip) that use select mode to position the curso
category:
config
tags:
#visual-mode
#normal-mode
#macros
How do I center the current line on screen and move to the first non-blank character?
Vim has two flavors of each screen-repositioning command: one that only moves the view and one that also repositions the cursor.
category:
navigation
tags:
#navigation
#normal-mode
#scrolling
How do I paste the contents of a register as a new line below the cursor regardless of the register type in Vim?
The :put Ex command always inserts a register's content as a new line below the current line, regardless of whether the register holds characterwise, linewise,
category:
editing
tags:
#registers
#editing
#paste
#ex-commands
#normal-mode
How do I append yanked text to an existing register without overwriting it in Vim?
Using an uppercase register letter with any operator appends to the register instead of replacing it.
category:
registers
tags:
#registers
#yank
#delete
#editing
#normal-mode
What is the difference between zt and z-Enter when scrolling the current line to the top of the screen?
Both zt and z scroll the view so that the current line lands at the top of the screen, but they differ in one small but important way: z also moves the cursor t
category:
navigation
tags:
#navigation
#normal-mode
How do I get a brief visual flash to confirm what text was just yanked in Neovim?
After yanking text in Vim it can be hard to tell exactly what was captured, especially with larger motions or text objects.
category:
config
tags:
#registers
#config
#normal-mode