How do I switch from typing a command to the full command-line window so I can edit it with all normal Vim keys?
<C-f> (from command-line)
When you are already in the middle of typing a command (after pressing :) and realize you need to compose something complex — a long substitution, a multi-pip
category:
command-line
tags:
#command-line
#editing
#normal-mode
How do I jump between matching #if, #else, and #endif preprocessor directives in C code?
Vim includes built-in motions for navigating C preprocessor conditional blocks: [# jumps backward to the previous unmatched #if or #else, and ]# jumps forward t
category:
navigation
tags:
#navigation
#normal-mode
#motions
How do I navigate to an older undo state that is not on my current undo branch?
Vim's undo history is a tree, not a linear stack.
category:
editing
tags:
#undo-redo
#navigation
#normal-mode
How do I hard-wrap a paragraph to fit within textwidth without moving my cursor away from it?
The gw operator reformats text to fit within 'textwidth' — identical in effect to gq, but with one key difference: the cursor returns to its original position
category:
editing
tags:
#editing
#formatting
#text-objects
#normal-mode
How do I use a macro to automatically increment a number on each line?
By recording a one-step macro that increments a number and moves down a line, you can bulk-apply across as many lines as needed with a single count.
category:
macros
tags:
#macros
#editing
#normal-mode
How do I use a count with a text object to operate on multiple words, sentences, or paragraphs at once?
Most Vim users know you can put a count before an operator (3dw) or use a text object once (daw).
category:
editing
tags:
#text-objects
#editing
#delete
#normal-mode
#motions
How do I enter a mode where I select text and then typing immediately replaces the selection, like in most graphical editors?
Vim's Select mode behaves like the familiar selection model in most GUI editors: after selecting text, any printable character you type replaces the selection a
category:
visual-mode
tags:
#visual-mode
#select-mode
#editing
#normal-mode
How do I replace only the current match and then stop when doing an interactive substitution in Vim?
l (in :%s///gc confirm prompt)
When running an interactive substitution with the c flag (e.
category:
editing
tags:
#search
#editing
#substitution
#ex-commands
#normal-mode
How do I change the cursor shape to a thin bar in insert mode and a block in normal mode in Neovim?
:set guicursor=n-v-c:block,i-ci-ve:ver25,r-cr:hor20
Neovim's guicursor option lets you assign a distinct cursor shape and style to each mode, providing immediate visual feedback about which mode you are in.
category:
config
tags:
#config
#normal-mode
#insert-mode
#visual-mode
How do I set up a local leader key for file-type-specific mappings that don't conflict with global mappings?
:let maplocalleader = ','
Vim provides two separate leader keys: (global) and (local to the current buffer).
category:
config
tags:
#config
#normal-mode
#ex-commands
How do I create a normal mode mapping that correctly captures and passes a count prefix to a function?
nnoremap <key> :<C-u>call MyFunc(v:count)<CR>
When writing custom mappings that call Vimscript functions, a common pitfall is that any count you type before the key (e.
category:
config
tags:
#config
#macros
#ex-commands
#normal-mode
How do I jump to the local or global declaration of the variable under the cursor without ctags?
Vim's gd and gD commands jump to the declaration of the identifier under the cursor by searching upward through the file — no ctags setup required.
category:
navigation
tags:
#navigation
#editing
#normal-mode
How do I edit a macro without re-recording it?
:let @q = substitute(@q, 'old', 'new', '')
Vim macros are stored as plain text in named registers, which means you can inspect and modify them directly using :let and :echo.
category:
macros
tags:
#macros
#registers
#editing
#normal-mode
How do I run a substitute or filter command without Vim automatically repositioning my marks?
When Vim executes commands that move or reorder lines — such as :sort, :%!sort, or :s/// across ranges — it automatically adjusts named marks to follow the
category:
command-line
tags:
#ex-commands
#marks
#editing
#normal-mode
How do I use a count with text objects to operate on multiple text objects at once?
Text objects in Vim accept a count, letting you operate on a span of multiple adjacent text objects in one command.
category:
editing
tags:
#editing
#text-objects
#normal-mode
How do I repeat a macro as many times as possible until it fails?
Prefixing a macro invocation with a large count like 999@q tells Vim to run register q up to 999 times.
category:
macros
tags:
#macros
#normal-mode
How do I close all folds and then open just the one containing the cursor to focus on it?
The zMzv sequence collapses every fold in the file and then re-opens only the one containing your cursor.
category:
editing
tags:
#folding
#navigation
#normal-mode
How do I force a case-insensitive substitution without changing the global ignorecase setting?
:%s/pattern/replacement/ig
The :s substitute command accepts /i and /I flags that override your global ignorecase and smartcase settings for that single substitution, letting you choose c
category:
search
tags:
#search
#editing
#ex-commands
#normal-mode
How do I close a preview window from any other window without having to jump to it first?
Pressing z closes the preview window from any window in the current tab page.
category:
buffers-windows
tags:
#windows
#buffers
#navigation
#normal-mode
How do I paste text before the cursor while leaving the cursor positioned after the pasted content?
The gP command works like P (paste before the cursor) but leaves your cursor after the pasted text rather than at its beginning.
category:
editing
tags:
#editing
#paste
#registers
#normal-mode