vim [filename/directory]
vim filename +123
or inside vim
:e [filename]
:edit [filename]
/regex search
?search backwards
/\(TODO\|FIXME\)
/\v(TODO|FIXME)
/todo/i
see :help regex
and :help magic
:%s/old/new/g
y<motion>
yank (copy)
d<motion>
delete (cut)
yy
yank a line
dd
delete a line
5dd
delete 5 lines
P
paste (before cursor)
p
paste (after cursor)
:write
:w
:quit
:q
:q!
:wq
ZZ
w
Forward a word (non-alpha)
W
Forward a word (space)
b
Back a word (non-alpha)
B
Back a word (space)
e
End of word (non-alpha)
E
End of word (space)
^
Home (1st character on line)
0
Home (beginning of line)
$
End (end of line)
<enter>
Down + Home (1st character)
-
Up + Home (1st character)
t☐
Go up to the character you type next, ex: t(
to the next (
T☐
Go up to the character you type next, backward
f☐
Find the character you type next
F☐
Find the character you type next, backward
;
Next t or f match
,
Previous t or f match
<number><command>
Repeat any movement or edit number times
j
down
k
up
h
left
l
right
H
Highest line on screen
M
Medium line on screen
L
Lowest line on screen
:100
Jump to line 100
*
Search for the word under the cursor (forward)
#
Search for the word under the cursor (backward)
i
Insert mode (before cursor)
I
Insert mode (beginning of line)
a
Append (insert after cursor)
A
Append (insert after cursor)
o
Open a new line (before cursor)
O
Open a new line (after cursor)
r☐
Replace the character under the cursor with ☐
R
Replace in insert mode - type over characters
J
Join lines with a space
gJ
Join lines
d<motion>
Delete (cut) to wherever you move next
D
Delete to the end of the line
c<motion>
Cchange to wherever you move next (delete + insert)
C
Cchange to the end of the line
x
Delete key
X
Backspace key
s
Swap the current character (x + insert)
S
Swap the current line (cc + insert)
xp
transpose teh-like typo (delete and paste-after)
.
Repeat the last edit
^E
Scroll down
^Y
Scroll up
^F
Forward a page (page down)
^B
Back a page (page up)
^U
Up 1/2 page
^D
Down 1/2 page
z<enter>
Scroll so cursor is at top of screen
zz
or z.
Scroll so cursor is at middle of screen
z-
Scroll so cursor is at bottom of screen
^W n
New window
^W s
Split window
^W k
or ^W <up>
Move cursor up a window
^W j
or ^W <down>
Move cursor down a window
^W c
or :q
Close window
:help ^W
:buffers
buffer list
:b partOfFilename
switch to buffer (tab-completable)
Opening a ton of files for use with buffers:
vi $(find . -type f)
vi * $(find rails_app/app -type f)
vim src/*
:next
or :n
next file
:prev
or :N
next file
:set spell
:help spell
qa
start recording macro a. Can use any letter
q
stop recording
@a
replay macro a
qA
append to macro a
Caveat: u
undo during recording won't act the same when played back, because playback acts as a single undo action. Don't use undo when recording.
Examples:
- adding --- to markdown
- restructuring html tables
==
Fix indentation on current line
>>
Indent current line
5>>
Indent 5 lines
>>
Indent current line
:set autoindent
or :set ai
:set cindent
My ~/.vimrc
Set config values in vim with :set foo=bar
Ex: :set tabstop=4 # make tabs 4 characters wide :set ts=4 # make tabs 4 characters wide :set paste # don't autoindent :set paste! # same as :set nopaste
!rm oldfile
:w !sudo tee %
:!javac %