Skip to content

Instantly share code, notes, and snippets.

@haikyuu
Last active December 24, 2018 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haikyuu/13ba74f41fd44a92fd124ac535afe065 to your computer and use it in GitHub Desktop.
Save haikyuu/13ba74f41fd44a92fd124ac535afe065 to your computer and use it in GitHub Desktop.
VIM cheatsheet

Netrw

SHORTCUT Description
o open file in horizontal split
v open file in vertical split
git diff Show file differences that haven't been staged
COMMAND Description
Vexplore open file tree in vertical split

Search and replace

Manual (Repeat substitution)

Hit the . key to perform an exact replay of the very last command (other than movement). For example, I type cw then hello to change a word to "hello". After moving my cursor to a different word, I hit . to do it again.

Auto

  • :s/foo/bar/g: Find each occurrence of 'foo' (in the current line only), and replace it with 'bar'.
  • :%s/foo/bar/gc: Change each 'foo' to 'bar', but ask for confirmation first.
  • :%s/\<foo\>/bar/gc: Change only whole words exactly matching 'foo' to 'bar'; ask for confirmation.

Copying to clipboard

select some text and yank it inside the * registry using: "*y Helpful: https://gist.github.com/squarism/ae3613daf5c01a98ba3a

Search across project

  • vimgrep keyword **/*.paths_here. This looks (sync) for occurences and populates the quickfix window.
  • Navigate through the quick fix using cn and cp
:copen " Open the quickfix window
:ccl   " Close it
:cn    " Go to the next error in the window
:cnf   " Go to the first error in the next file

ESLint

  • <C-k> and <C-j> to move back and forth in errors.
  • make to run eslint on the whole folder and populate quick fix list

Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment