Skip to content

My Curated 𝑽im Command Collection

vim-logo-png-transparent.png

"Entire swaths of the Salinas Valley have been upended with these Vim bindings.

I move through my manuscript like a nimble fruit picker through an orchard in full bloom.

Where once there were disorderly rows of dialogue and description, now lies carefully tended prose, rooted by deft keystrokes.

The ':w' command rings out like a foreman's whistle, saving the day's toil.

And lo, the great migration of paragraphs, from chapter to chapter, leaves this writer as dizzy as a field hand after a long day's harvest."

-John Steinbeck

Recording and Repeating Commands

  • Record a sequenceq n {command sequence} q
  • Repeat a sequence@ n

Basic Text Modification

  • Repeat last change.
  • Change inner wordciw (then type new word)
  • Increment numberCtrl a
  • Decrement numberCtrl x
  • Change case of character under cursor~
  • Open file from a path namegf
  • Move to a characterf {character}
  • Jump between matching HTML tags%

Windows and Splits

  • Split window horizontally:vs or :vsp {filename}
  • Split window verticallyCtrl w v or :vs {filename}
  • Resize windows to be equalCtrl w =
  • Move right between panesCtrl w l
  • Move left between panesCtrl w h
  • Toggle between panesCtrl w w
  • Resize horizontally:res {number}
  • Resize vertically:vertical resize {number}

Editing and Surrounding Text

  • Surround word with quotes or tagsc i w "" Esc p
  • Delete surrounding single quotes (w/ vim-surround plugin)d s '
  • Change surrounding character (w/ vim-surround plugin)c s {current} {new}

Clipboard Operations

  • Copy to system clipboard"*y
  • Paste from system clipboard"*p

Search and Replace

  • Replace in current line:s/{searchTerm}/{replacement}/g
  • Replace in entire document:%s/{searchTerm}/{replacement}/g
  • Replace within a visually selected block:s/{currentWord}/{newWord}/g

File Browsing with Netrw

  • Open netrw window:Ex
  • Horizontal split netrw:Sex
  • Vertical split netrw:Vex
  • Create a new directory in netrwd
  • Create a new file in netrw directory%
  • Open vertical split file previewp (when file is highlighted)

Folding (Collapsing) Code

  • New foldzfat
  • Toggle an existing foldza
  • Open all folds in documentzR
  • Close all folds in documentzM

Marks and Jumps

  • Set a markm {a-z}
  • Jump to a mark' {a-z} or `` {a-z}`
  • Jump to the previous location''

Running Commands and Scripts

  • Run current JS script in Node:w !node %
  • Search within files with greplike command:Rg {searchTerm}

Colorschemes

  • Change colorscheme:colo {colorscheme}
  • Install a colorscheme(copy colorscheme vim file into ~/.vim/colors)
  • Enable true colors in terminalset termguicolors (in .vimrc)

Emmet Commands

  • Self-closing tags for Reactcustomtag/ (converts to <customtag />)

Macros

  • Record a macroq {register} {commands} q
  • Playback a macro@ {register}

Miscellaneous

  • Check spellingz=
  • Select text inside surrounding characterv i {character}
  • Yank (copy) text inside surrounding charactery i {character}
  • Select a whole wordv i w
  • Add line above currentO
  • Add line below currento
  • Join line below with current lineJ
  • Set netrw to directory below cursorgn
  • Move cursor vertically by half window heightCtrl + u / Ctrl + d