Vim Editor Cheat Sheets : Daily Use ShortCuts

Useful Vim start arguments

  1. -g : run using GUI
  2. -d : diff mode
  3. -R : read only mode
  4. -m : modifications (writing files) not allowed
  5. -M : modifications not allowed
  6. -b : binary mode
  7. -n : no swap files, use memory only
  8. -r <with file name> : Recover crashed session
  9. -u <vimrc> : use <vimrc> of your choice, instead of default .vimrc
  10. -U <gvimrc> : use <gvimrc> of your choice, instead of default .gvimrc
  11. -p[N] : Open N tab pages, (default : one for each file)
  12. -o[N] : Open N window pages, (default : one for each file)
  13. -O[N] : Open N window pages, split vertically
  14. + : start at the end of file
  15. +<line-number> : start at the <lin-number> in the given file

Useful GUI Vim start arguments

  1. -background <color> : use <color> for the background (shortform : -bg)
  2. -foreground <color> : use <color> for the foreground (shortform : -fg)
  3. -font <font> : use <font> for normal text (shortform : -fn)

Marks in vim

  1. :marks : view all current marks
  2. ma : Normal mode : type m followed by mark character. example : ma – marks the current postion and maps it to a character
  3. `<mark-character> : go to marked position stored in <mark-character>. So, if I set a mark with ma, then `a will take me to location marked with character a
  4. :delm <mark-characters> : to delete marks. If you have marks set to a, b, c , D..then you can delete it with :delm abcD
  5. :delm! : deletes all the marks
  6. `” : go to the position, when last editing this file
  7. `. : go the position of last change of this file
  8. : go to the position of the last change of this file
  9. :ju[mps] : list of jumps
  10. Ctrl + i : go to newer position in jump list –  can be used with Ctrl + o to loop between current and last positions
  11. Ctrl + o : go to older position in jump list –  can be used with Ctrl + i to loop between current and last positions
  12. :changes  : list of changes
  13. g, : go to newer position in the changelist
  14. g; : go to older position in the changelist
  15. Ctrl + ] : jump to tag under cursor

Motions in VIM

Key Motion Direction Key Motion Direction Key Motion Direction Key Motion Direction
h Move Cursor Left j Move Cursor Down k Move Cursor Up l Move Cursor Right
H Move To Top Of Screen gj Move Cursor Down (multi line text) gk Move Cursor Up (multi line text) M Move To Middle Of Screen
L Move To Bottom Of Screen w/W jump to start of next word e/E jump to end of next word b/B jump to back to start of word
ge/gE jump backward to end of word % move character to matching bracket/braces 0 Jump to start of line ^ Jump to first nonblank character
of a line
$ jump to end of line g_ jump to last nonblank character of a line gg Go to the first line of document G go to last line of document
5gg/5G go to line 5 fx jump to next occurrence of character ‘x’ tx jump before occurrence of character ‘x’ Fx jump previous occurrence of
character x
Tx Move before last occurrence of character ‘x’ ; repeat previous search f,F,t,T , repeat previous search f,F,t,T backwards } jump to next paragraph (function block)
{ jump to previous paragraph (function block) zz move current line to center of screen zt move current line to top of screen zb move current line to bottom of screen
Ctrl + e move page up by one line Ctrl + y move page down by one line Ctrl + f Move Forward By One Screen Ctrl + b Move Backward By On Screen
Ctrl + d Move forward by half Page Ctrl + u Move Backward by Half Page

 

Search and Delete a line

  1. g/search-term/d : d is the command to delete
  2. dd : delete an entire line
  3. gnd : delete last searched term. Entire word can be repeated with . dot command
  4. diw : delete inside a character, eg. di” – will delete everything between ” (double quotes)
  5. daw : delete a word, you can delete a word , when you are inside first and last character of a word
  6. ciw : change a word, go into insert mode and run the change command

 

Related Post