Vi Tips & Tricks

Scott's VI Tips and Tricks - Be more productive with less key strokes!!!

MODES:
Command  This is where you issue commands like movement, editing, ...
:    issue command

Insert
i,I    insert before character/line
a,A    insert after character/line
o,O    insert after/before line
s,S    delete character/line then insert
C      delete rest of line then insert

Replace
R      replace current text

Visual
v      highlight by character
V      highlight by line
^v     highlight by block

MOVEMENT:
by character
    k
h       l
    j

by page
Ctrl+f  page forward
Ctrl+b  page back

by line
G      last line of file
<#>G   jump to line
gg     top line
0      beginning of line
$      end of line
H      first line on page
L      last line on page

by word
w,W    next beginning of word
e,E    next end of word
b,B    previous beginning of word 

with bookmarks
m<i>   set bookmark, where i=a,b,c,d ..
,<i>   jump to mark

EDITING:
copy,cut,paste
y      yank + <movement>
p,P    put below/above
note: put works after delete too

deleting
r     replace current character
x,X   delete character right/left
D     delete to end of line
dd    delete line

combos
dW    delete word
d3W   delete 3 words
y3y   yank 3 lines
d'a   delete to mark-a

misc
~     toggle case
J     join the next line

SEARCHING:
basic search
/     search down using REGEXP
?     search up using REGEXP
#     next match of word
K     will lookup man page for a command 

USING COMMANDS
: <command>
find and replace
:s/old/new      first occurance - current line
:s/old/new/2    first occurance - 2 lines
:%s/old/new     first occurance - all lines
:i,j s/old/new  first occurance - from lines i to j
:%s/old/new/g   all occurances  - all lines

vi settings
:set nu         display line numbers
:set list       show all characters
:set ignorecase 

external command
:!<cmd>    issue external shell command
!!         insert the stdout of shell command

read in file
:r <filename>

changing files
:n,N      next/previous