Skip to content
Vim & Neovim Cheat Sheet

Vim & Neovim Cheat Sheet

A curated reference of everyday Vim and Neovim navigation, substitution, sorting, window management, and plugin shortcuts.

General Shortcuts

KeyAction
"+yCopy to OS system clipboard
:norm A [text]Append text at the end of each selected line in normal mode
:verbose imap <key>Inspect which plugin/config mapped a key in insert mode
:verbose nmap <key>Inspect which plugin/config mapped a key in normal mode

Basic Word Navigation

  • w - Move the cursor forward to the beginning of the next word.
  • b - Move the cursor backward to the beginning of the current or previous word.
  • e - Move the cursor forward to the end of the current or next word.

Search & Substitution

Single File Substitution

:[range]s/search/replace/[flags]
  • range (optional): Range of lines to apply substitution:
    • %: Entire file.
    • 1,5s: Lines 1 through 5.
    • .,+10s: From current line to 10 lines down.
  • search: Target string or regular expression pattern.
  • replace: Replacement string.
  • flags (optional):
    • g: Global (replace all occurrences per line, not just the first).
    • i: Case-insensitive search.
    • c: Confirm each substitution interactively.

Multi-Buffer Substitution (Across All Open Buffers)

:bufdo %s/old_pattern/new_pattern/gce | update
  • :bufdo: Executes the subsequent command across every buffer in the buffer list.
  • gce: Flags:
    • g: Replace all occurrences per line.
    • c: Confirm each substitution interactively.
    • e: Suppress errors if the pattern is not found in a buffer.
  • update: Writes and saves the file only if modifications were made.

Sorting (sort)

Basic Syntax

:[range]sort[!] [options] [/{pattern}/]

Ranges

CommandDescription
:%sortSort the entire file.
:10,20sortSort lines 10 through 20.
:'<,'>sortSort the current visual selection (automatically entered after selecting).
:.,+5sortSort from the current line to 5 lines down.

Common Flags

FlagDescriptionExample
! or rReverse the sort order.:%sort!
uUnique: remove duplicate lines.:%sort u
nNumeric: sort based on the first decimal number in the line.:%sort n
iIgnore case.:%sort i
fFold case: similar to i but respects 'ignorecase' setting.:%sort f
xSort based on the first hexadecimal number.:%sort x
oSort based on the first octal number.:%sort o
bSort based on the first binary number.:%sort b

Combining Flags

" Reverse, numeric, unique sort
:%sort! nu

" Case-insensitive unique sort
:%sort ui

Buffers, Windows, and Tabs

Concepts

  • Buffers: In-memory representations of files. Opening a file loads it into a buffer.
  • Windows: Viewports into buffers. Multiple windows can view different buffers (or different parts of the same buffer) simultaneously.
  • Tabs: Collections or layouts of windows.

Navigation

KeyAction
gtNext tab
gTPrevious tab
<S-l>Next buffer
<S-h>Previous buffer
:bwipeout (or :bw)Delete and remove buffer from buffer list

Plugins & LSP

LSP

KeyAction
:LspInfoDisplay status and attached clients of the LSP server

nvim-surround

KeyActionExample
ys<motion><delimiter>Add surroundingysiw" wraps word in ""
cs<old><new>Change surroundingcs"' changes "" to ''
ds<delimiter>Delete surroundingds" removes surrounding ""

nvim-tree

KeyActionDescription
<CR>editOpen file/folder; root will cd to parent directory
<C-v>vsplitOpen file in vertical split
<C-x>splitOpen file in horizontal split
<C-t>tabnewOpen file in new tab
<prev_siblingNavigate to previous sibling
>next_siblingNavigate to next sibling
Pparent_nodeMove cursor to parent directory
<BS>close_nodeClose current opened directory or parent
<Tab>previewOpen file preview without moving focus from tree
RrefreshRefresh tree
acreateAdd file (trailing / creates directory)
dremoveDelete file/directory (with confirmation)
DtrashTrash file via system trash
rrenameRename file
<C-r>full_renameFull rename (omits original filename on input)
erename_basenameRename without modifying extension (:t:r)
xcutCut file/directory to clipboard
ccopyCopy file/directory to clipboard
ppastePaste from clipboard
ycopy_nameCopy filename to system clipboard
Ycopy_pathCopy relative path to system clipboard
gycopy_absolute_pathCopy absolute path to system clipboard
ssystem_openOpen with system default application / file manager

Telescope & treesj

  • :Telescope keymaps — Interactive fuzzy finder for active key mappings.
  • treesj commands — Split and join code blocks using tree-sitter.