Skip to content

Instantly share code, notes, and snippets.

@seven1m
Created April 22, 2009 17:51
Show Gist options
  • Save seven1m/99947 to your computer and use it in GitHub Desktop.
Save seven1m/99947 to your computer and use it in GitHub Desktop.
# I am learning VIM - here is what I've learned.
# A great reference is here: http://www.cs.runet.edu/~mhtay/CPSC120/VIM_Editor_Commands.htm
# (but I didn't just copy from there -- I tried each one first, and saved the ones my brain might remember here)
# basics
i # insert (edit) mode
o # "open" new line and insert (edit) mode there
ESC # command mode
:help # get help in a split window (:q to close)
:help topic # get help on a topic
# open, close files
:e filename # edit filename
:w filename # write to filename
:w # save changes to current file
:wq # write and close file
:q # close file
# cursor navigation
gg # move to beginning of file
G # move to end of file
^ or 0 # move to beginning of line
$ # move to end of line
10{arrowkey} # move the cursor 10 characters/lines in the direction of the arrow key
w # forward one word
b # back one word
:10 # moves to line 10 in file
v # select text (line mode)
CTRL+v # select text (block mode)
# cut, copy, paste
dd # cut line (delete and cut are same thing)
2dd # cut 2 lines
d # cut (must select first with v or ctrl+v)
yy # copy line or selection (called yank)
2yy # copy 2 lines
P # paste
"2P # paste previous clipboard (there are 9)
p # paste below cursor - use Yppp to quickly duplicate the current line 3 times
# delete
dw # delete to end of word
d$ # delete to end of line
d^ # delete to beginning of line
# find, replace
/term # search
/ # repeat least search
:s/old/new/g # replace in current line
:%s/old/new/g # replace in entire file
# indent, unindent (first use v or ctrl+v to select)
> # indent selected lines
< # unindent selected lines
2> # indent 2 times
2< # unindent 2 times
# tabs
vim -p filename1 filename2 # open files in tabs
gt # go to next tab
:tabfirst # move to first tab
:tablast # move to last tab
:tabnew filename # open new tab
:wq # write and close tab
:q # close tab
:qa # close all tabs
# split window
:sp # splits window and duplicates same file in both sections
:vsp # splits window vertically and duplicates same file in both sections
:sp filename # splits window and opens filename in top section
:vsp filename # splits window vertically and opens filename in top section
CTRL+w x2 # switch between split sections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment