Skip to main content

Vim Cheat Sheet

Motions

ShortcutAction
0gGo to beginning of file
GGo to end of file
^Go to beginning of line
$Go to end of line
J(Visual) - move selection down
K(Visual) - move selection up
AMove to end of line and insert
<C-d>Half page jump down
<C-u>Half page jump up

Project

ShortcutAction
<leader>pvNav to netrw
<leader>pfProject find (telescope)
<C-p>Find files only tracked in git
<leader>psSearch project files with grep
:e path/to/file.txt(netrw) - Create file in specified path

External Commands

ShortcutAction
:!Type a command after the bang to execute in the shell
:! lsExecute ls in the current working tree.
:r <file>Retrieves the specified file and places contents below cursor
:r !lsRetrieves the output of the external command and places contents below cursor

Workspace

ShortcutAction
<C-w><C-w>Jump between windows
<C-w>hMove split window on the left
<C-w>jMove split window on the down
<C-w>kMove split window on the up
<C-w>lMove split window on the right

Editing

ShortcutAction
:%s/Search/Replace/CommandFlagSearch and replace all occurances
:s/Search/Replace/CommandFlagSearch and replace current line
oInsert line below cursor
OInsert line above cursor
aInsert text AFTER the cursor
AInsert text at the end of the line
:e!Discard current edit buffer and re-read current file
r<char>Replace under cursor with <char>
REnter replace mode. <Esc> to exit
cChange operator
ceChange from cursor to end of current word
o<C-r>"Insert new line and then paste from " register

Fighting One-Eyed Kirby

Example Code Block
use("folke/zen-mode.nvim")
use("github/copilot.vim")
  • <shift>V Visual Line
  • j motion down for selection
  • :s Enter command mode
Regex search/replace
:'<,'>s/use(\(".*"\).*/\1
Result Code Block
"folke/zen-mode.nvim"
"github/copilot.vim"

Explanation

  • :s Search and replace
  • / Start pattern
  • use(\ Search for string literal
  • (".*"\) Regex to capture everything and place into capture group 1
  • .* Regex to capture everything after the first capture group
  • / Substitute section
  • \1 Escape and then replace with capture group 1

Spell Check

ShortcutAction
]sMove cursor to next misspelled word
[sMove cursor to previous misspelled word
z=Open list of spelling suggestions for word under cursor
zgAdd word to dictionary
zwMark word as incorrect

LSP

ShortcutAction
<C-p>select previous item
<C-n>select next item
<C-y>confirm selection
<C-Space>complete

Harpoon

ShortcutAction
C-eToggle harpoon menu
<leader>aAdd file
C-hNav to file 1
C-jNav to file 2
C-kNav to file 3
C-lNav to file 4

Fugitive (Git)

ShortcutAction
<leader>gsgit status
ccgit commit
cagit --amend
ddgit diff
qClose git status
rReload git status
<leader>pgit push
<leader>Pgit pull --rebase
<leader>tgit push -u origin