My commonly used vi shortcut keys:
Tutorials
VIM Introduction and Tutorial (link)
VI Cheat Sheet (link)
VIM Tips (link)
Code Merging with VIM (link)
VIM Tips and Tricks (cs.oberline.edu)
Command | Action | Notes |
Basic operations | ||
:q | Quit VI | This will exit VI editor |
:q! | Force quit | This will exit VI editor even if buffers are dirty |
:w | Save current buffer | Save currently active buffer |
:e <ENTER> | Reload current buffer from file | |
:e /path/to/file | Load /path/to/file to a buffer | |
General | ||
:set nowrap | Don't wrap text | |
:set number | Show line number | |
:set nu | Show line number (short hand) | |
:set nonumber | Hide line number | |
:set nu! | Hide line number (short hand) | |
Text Operations | ||
v | Start Visual Mode(for copying) | |
y | Yank/copy selected text | |
yy | Copy line | |
2y | Copy 2 lines from the cursor | |
p | Paste _after_ the current line | |
P | Paste _before_ the current line | |
x | Delete char under the cursor | |
dw | Delete the word under the cursor | This will also delete the space after it |
3dw | Delete 3 words | This will also delete the space after it |
dd | Delete line | Deletes the entire line |
Navigation | ||
0 | Jump to beginning of line | |
$ | Jump to end of line | |
w | (count)Move to beginning of the word | |
b | Move to the beginning of the word | |
e | Move to the end of the word (punctuation considered part of the word) | |
ge | Jump to previous word ending | |
gE | Jump to previous word ending, ignore punctuation | |
gg | Start of file | |
G | End of file | |
21G | Go to line 22 | |
Search and Replace | ||
/{string}{ENTER} | Search for string | |
:%s/foo/bar/g | Search for foo and replace with bar in the current buffer | |
Merging | ||
Note** run vimdiff file1 file2 | ||
]c | Jump to the next difference | |
[c | Jump to the previous difference | |
do | Copy line diff from _right_ buffer to the _left_ buffer | |
dp | Copy line diff from _left_ buffer to the _right_ buffer | |
Buffer operations | ||
:bd | Delete current buffer | |
:bnext | Move to next buffer | |
:bprevious | Move to previous buffer | |
:b <tab> | Tab select buffers | |
:ls | List buffers (or :buffers or :files) | |
:ls <CR> :bx | List buffers and then select buffer "x" | |
Multiple Windows | ||
C-w C-w | Move cursor to another window (cycle). Useful with NerdTree |
Tutorials
VIM Introduction and Tutorial (link)
VI Cheat Sheet (link)
VIM Tips (link)
Code Merging with VIM (link)
VIM Tips and Tricks (cs.oberline.edu)
Comments