Skip to content

Instantly share code, notes, and snippets.

@tiste
Forked from m3nd3s/NERDTree.mkd
Created October 2, 2013 15:51
Show Gist options
  • Save tiste/6795912 to your computer and use it in GitHub Desktop.
Save tiste/6795912 to your computer and use it in GitHub Desktop.
Vim cheat sheet

Cursor movement

h - move left
j - move down
k - move up
l - move right
% - jump to matching brace
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)
ge - jump backward to end of words (punctuation considered words)
gE - jump backward to end of words (no punctuation)
0 - (zero) start of line
$ - end of line
gg - Go to first line
<N>G - Go To line N. No N: last line

Note: Prefix a cursor movement command with a number to repeat it

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
Esc - exit insert mode

Editing

r - replace a single character
J - join line below to the current one
cc OR S - change (replace) an entire line
s - delete character at cursor and subsitute text
u - undo
ctrl-r - redo
. - repeat last command
~ - switch case
>> - indent line one column to right
<< - indent line one column to left
== - auto-indent current line

Cut and Paste

dd - delete (cut) a line
dw - delete the current word
x - delete current character
X - delete previous character
D - delete from cursor to end of line
yy - yank (copy) a line
yw - yank word
y$ - yank to end of line
p - put (paste) the clipboard after cursor/current line
P - put (paste) before cursor/current line

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
:n **/*.pl - Open all perl files under the current directory, recursively
:tabe filename - Edit a file in a new tab (Vim7, gVim)
:bnext (or :bn) - go to next buffer
:bprev (or :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-w s - Split windows
ctrl-w w - switch between windows
ctrl-w q - Quit a window
ctrl-w v - Split windows vertically

Tabs

{i}gt  - go to tab in position i
gt - Next tab
gT - Previous tab
:tabr - First tab
:tabl - Last tab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment