Skip to content

Instantly share code, notes, and snippets.

@som-poddar
Last active November 30, 2017 23:05
Show Gist options
  • Save som-poddar/c54e1864cf9f39ef484ee7fdadcad375 to your computer and use it in GitHub Desktop.
Save som-poddar/c54e1864cf9f39ef484ee7fdadcad375 to your computer and use it in GitHub Desktop.
Cheat Sheets

Cursor movement

  • h - move left
  • j - move down
  • k - move up
  • l - move right
  • w - jump by start of words (punctuation considered words) W - jump by words (spaces separate words)
  • e - jump to end of words (punctuation considered words)
  • E - jump to end of words (no punctuation)
  • b - jump backward by words (punctuation considered words) B - jump backward by words (no punctuation)
  • 0 - (zero) start of line
  • ^ - first non-blank character of line
  • $ - end of line
  • G - Go To command (prefix with number - 5G goes to line 5)

Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines.

Insert Mode - Inserting/Appending text

  • 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

Editing

  • r - replace a single character (does not use insert mode) J - join line below to the current one
  • cc - change (replace) an entire line
  • cw - change (replace) to the end of word
  • c$ - change (replace) to the end of line
  • s - delete character at cursor and subsitute text
  • S - delete line at cursor and substitute text (same as cc) xp - transpose two letters (delete and paste, technically) u - undo
  • . - repeat last command

Marking text (visual mode)

  • v - start visual mode, mark lines, then do command (such as y- yank)
  • V - start Linewise visual mode
  • o - move to other end of marked area
  • Ctrl+v - start visual block mode O - move to Other corner of block aw - mark a word
  • ab - a () block (with braces)
  • aB - a {} block (with brackets)
  • ib - inner () block
  • iB - inner {} block
  • Esc - exit visual mode

Visual commands

    • shift right
  • < - shift left
  • y - yank (copy) marked text d - delete marked text
  • ~ - switch case

Cut and Paste

  • yy - yank (copy) a line
  • 2yy - yank 2 lines
  • yw - yank word
  • y$ - yank to end of line
  • p - put (paste) the clipboard after cursor P - put (paste) before cursor
  • dd - delete (cut) a line
  • dw - delete (cut) the current word
  • x - delete (cut) current character

Exiting

  • :w - write (save) the file, but don't exit :wq - write (save) and quit
  • :q - quit (fails if anything has changed) :q! - quit and throw away changes

Search/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

Working with multiple files

  • :e filename - Edit a file in a new buffer :bnext (or :bn) - go to next buffer :bprev (of :bp) - go to previous buffer :bd - delete a buffer (close a file)
  • :sp filename - Open a file in a new buffer and split window ctrl+ws - Split windows
  • ctrl+ww - switch between windows
  • ctrl+wq - Quit a window
  • ctrl+wv - Split windows vertically

Window Resize

Ctrl+W, _ will maximize a window vertically. Ctrl+W, | will maximize a window horizontally. Ctrl+W, = will resize all windows to equal sizes.

NERDTree

o.......Open files, directories and bookmarks....................|NERDTree-o|
go......Open selected file, but leave cursor in the NERDTree.....|NERDTree-go|
t.......Open selected node/bookmark in a new tab.................|NERDTree-t|
T.......Same as 't' but keep the focus on the current tab........|NERDTree-T|
i.......Open selected file in a split window.....................|NERDTree-i|
gi......Same as i, but leave the cursor on the NERDTree..........|NERDTree-gi|
s.......Open selected file in a new vsplit.......................|NERDTree-s|
gs......Same as s, but leave the cursor on the NERDTree..........|NERDTree-gs|
O.......Recursively open the selected directory..................|NERDTree-O|
x.......Close the current nodes parent...........................|NERDTree-x|
X.......Recursively close all children of the current node.......|NERDTree-X|
e.......Edit the current dif.....................................|NERDTree-e|

<CR>...............same as |NERDTree-o|.
double-click.......same as the |NERDTree-o| map.
middle-click.......same as |NERDTree-i| for files, same as
                  |NERDTree-e| for dirs.
I.......Toggle hidden file 

D.......Delete the current bookmark .............................|NERDTree-D|

P.......Jump to the root node....................................|NERDTree-P|
p.......Jump to current nodes parent.............................|NERDTree-p|
K.......Jump up inside directories at the current tree depth.....|NERDTree-K|
J.......Jump down inside directories at the current tree depth...|NERDTree-J|
<C-J>...Jump down to the next sibling of the current directory...|NERDTree-C-J|
<C-K>...Jump up to the previous sibling of the current directory.|NERDTree-C-K|

C.......Change the tree root to the selected dir.................|NERDTree-C|
u.......Move the tree root up one directory......................|NERDTree-u|
U.......Same as 'u' except the old root node is left open........|NERDTree-U|
r.......Recursively refresh the current directory................|NERDTree-r|
R.......Recursively refresh the current root.....................|NERDTree-R|
m.......Display the NERD tree menu...............................|NERDTree-m|
cd......Change the CWD to the dir of the selected node...........|NERDTree-cd|

I.......Toggle whether hidden files displayed....................|NERDTree-I|
f.......Toggle whether the file filters are used.................|NERDTree-f|
F.......Toggle whether files are displayed.......................|NERDTree-F|
B.......Toggle whether the bookmark table is displayed...........|NERDTree-B|

q.......Close the NERDTree window................................|NERDTree-q|
A.......Zoom (maximize/minimize) the NERDTree window.............|NERDTree-A|
?.......Toggle the display of the quick help.....................|NERDTree-?|

Links:

KEY MAPPINGS tagbar-keys

The following mappings are valid in the Tagbar window:

/? Display key mapping help. Map option: tagbar_map_help / Jump to the tag under the cursor. Doesn't work for pseudo-tags or generic headers. Map option: tagbar_map_jump p Jump to the tag under the cursor, but stay in the Tagbar window. Map option: tagbar_map_preview P Open the tag in a |preview-window|. Map option: tagbar_map_previewwin When on a fold icon, open or close the fold depending on the current state. <2-LeftMouse> Same as . See |g:tagbar_singleclick| if you want to use a single- instead of a double-click. Go to the next top-level tag. Map option: tagbar_map_nexttag Go to the previous top-level tag. Map option: tagbar_map_prevtag Display the prototype of the current tag (i.e. the line defining it) in the command line. Map option: tagbar_map_showproto v Hide tags that are declared non-public. Tags without any visibility information will still be shown. Map option: tagbar_map_hidenonpublic +/zo Open the fold under the cursor. Map option: tagbar_map_openfold -/zc Close the fold under the cursor or the current one if there is no fold under the cursor. Map option: tagbar_map_closefold o/za Toggle the fold under the cursor or the current one if there is no fold under the cursor. Map option: tagbar_map_togglefold */zR Open all folds by setting foldlevel to 99. Map option: tagbar_map_openallfolds =/zM Close all folds by setting foldlevel to 0. Map option: tagbar_map_closeallfolds zr Increase the fold level of the buffer by 1. Opens all folds one level. Map option: tagbar_map_incrementfolds zm Decrease the fold level of the buffer by 1. Closes all folds one level. Map option: tagbar_map_decrementfolds zj Go to the start of the next fold, like the standard Vim |zj|. Map option: tagbar_map_nextfold zk Go to the end of the previous fold, like the standard Vim |zk|. Map option: tagbar_map_prevfold s Toggle sort order between name and file order. Map option: tagbar_map_togglesort c Toggle the |g:tagbar_autoclose| option. Map option: tagbar_map_toggleautoclose x Toggle zooming the window. Map option: tagbar_map_zoomwin q Close the Tagbar window. Map option: tagbar_map_close Links: 1. http://www.fprintf.net/vimCheatSheet.html

Cursor Movement Insert Mode Editing
h - move left i - start insert mode at cursor r - replace a single character (does not use insert mode)
j - move down I - insert at the beginning of the line J - join line below to the current one
k - move up a - append after the cursor cc - change (replace) an entire line
l - move right A - append at the end of the line cw - change (replace) to the end of word
w - jump by start of words [1.] o - open (append) blank line below c$ - change to the end of line
W - jump by words [2.] O - open blank line above S - delete line at cursor and substitute text (same as cc)
e - jump to end of words [1] ea - append at end of word p - paste after
E - jump to end of words [3] Esc - exit insert mode P - paste After
b - jump backward by words [1] . - repeat last command xp - transpose (delete and paste)
B - jump backward by words [3] u - undo
0 - (zero) start of line
^ - first non-blank character of line
$ - end of line
G - Go To command

Note:

  1. punctuation considered words
  2. spaces separate words
  3. no punctuation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment