Skip to content

Instantly share code, notes, and snippets.

@codingPingjun
Last active February 12, 2019 10:16
Show Gist options
  • Save codingPingjun/672fa844c54429c9d44894c154e5ae74 to your computer and use it in GitHub Desktop.
Save codingPingjun/672fa844c54429c9d44894c154e5ae74 to your computer and use it in GitHub Desktop.
Vim Command

Vim Cheat Sheet

File Operation

:o file - open file

:w file - save file as

:close - close current pane

Cursor Movement

^ - go to first character of the line

$ - jump to the end of the line

5G - go the line 5

G - got to last line

Ctrl + b - move back one full screen

Ctrl + f - move forward one full screen

Ctrl + d - move forward 1/2 screen

Ctrl + b - move back 1/2 screen

Editing

u - undo

Ctrl + r - redo

. - repeat last command

Cut and Paste

yy - copy a line

2yy - copy 2 lines

yw - copy a word

y$ - copy to end of the line

p - put the clipboard after cursor

dd - delete a line

2dd - delete two lines

dw - delete a word

d$ - delete to the end of the line

Search and Replace

/pattern - search for pattern

?pattern - search backward for pattern

n - repeat search in the same direction

:%s/old/new/g - replace all old with new throughout file

:%s/old/new/gc - replace throughout file with confirmation

Working with Multiple Files

:e filename - edit a file in new buffer

:bn - go to the next buffer

:bp - go to previous buffer

:sp filename - open a file in a new buffer and split window

:vsp filename - open a file in a new buffer and vertically split window

Ctrl + ws - split window

Ctrl + ww - switch window

Ctrl + wq - quit a window

Ctrl + wv - split window vertically

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