Skip to content

Instantly share code, notes, and snippets.

@cracell
Last active September 27, 2015 19:08
Show Gist options
  • Save cracell/1317905 to your computer and use it in GitHub Desktop.
Save cracell/1317905 to your computer and use it in GitHub Desktop.
VIM Cheatsheet (A Work in progress)

VIM Cheatsheet

Remember VIM is all about combining commands. These are just the basics with a few combination examples.

Tutor - vimtutor from command line

Insert Mode

  • i - start insert mode at cursor
  • I - insert at the beginning of the line
  • a - append after the cursor
  • A - append at the end of the line
  • o - open (append) blank line below current line (no need to press return)
  • O - open blank line above current line
  • ea - append at end of word
  • Esc - exit insert mode
  • Ctrl-[ - escape
  • S - delete line and go into insert mode
  • xp - Swap current character with the next one
  • df then the character you want to delete to (and it deletes that character)

Panes

  • CTRL+w + direction : Changes the focused pane.

Editing

  • u - undo
  • CTRL+r - redo
  • r - replace a single character (does not use insert mode)
  • J - join line below to the current one
  • dd - Delete the line (d2d deletes two lines, d3d deletes three lines, etc.)

Cutting, Copying and Pasting

  • yy - yank (copy) a line
  • 2yy - yank 2 lines
  • "ayy - this will store the line in buffer a
  • "ap - this will put the contents of buffer a at the cursor.
  • "a5yy - this will store the 5 lines in buffer a

Navigating

  • H : To the first line of the screen.
  • M : To the middle line of the screen.
  • L : To the the last line of the screen.
  • 42G : Goto Line 42
  • 42gg: Goto Line 42
  • :42 : Goto Line 42
  • CTRL+d : Goes down half a page
  • ^ - first non-blank character of line
  • $ - last character of a line
  • G - End of File

Visual Mode

ctrl + v - Visual block mode

Find and Replace

  • /pattern - search for pattern
  • ?pattern - search backward for pattern
  • n - repeat search in same direction
  • N - repeat search in opposite direction
  • :%s/old/new/g - replace all old with new throughout file
  • :%s/old/new/gc - replace all old with new throughout file with confirmations
  • :%s/foo/bar/gc
  • :%s/foo/bar/gc
  • :5,20s/foo/bar/ - replace line 5 to 20 foo with bar
  • :./foo/bar/ - replace current line
  • :.,+100s/foo/bar/ - replace next 100 lines from current

Settings

colorscheme ir_black #change colorscheme

##Window Ctrl + W #Intro window mode Ctrl + W then h,j,k, or l to choose what direction window to change focus too Ctrl + W then Shift + h, j, k, or l to move the window to that side of the screen.

Nerdtree

s # When over the file use s to open it in a vertically split pane.

@cracell
Copy link
Author

cracell commented Oct 27, 2011

@cracell
Copy link
Author

cracell commented Oct 27, 2011

@cracell
Copy link
Author

cracell commented Oct 31, 2011

@cracell
Copy link
Author

cracell commented Nov 2, 2011

@cracell
Copy link
Author

cracell commented Nov 3, 2011

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