# Vim

* $ vim xxx yyy zzz - open one or more files
* (-R: open as read-only; +n: skip to line n; +/xxx: skip to string xxx;)
vim . - browse current directory

### Modes

esc - goto command mode
i,I,a,A,o,O - goto insert mode
v,V,Ctrl+v - goto visual mode

### Colon Commands

w - save
w myfile - save as myfile
q - quit
r myfile - paste myfile at the cursor of the current file
e myfile - edit myfile, close current file
f - show file properties
n - open next vi file in arguments list
!xxx - run xxx in the shell
!!xxx - replace current line with result of shell command xxx
!}xxx - replace current paragraph with the result shell command xxx
map - show key mappings
map key cmd - map vi cmd to key
. - show line numbers
set nonumber - turn off line numbering
    s/old/new/ - search and replace
%s/search/&/g - search and count matches
1,$ s/old/new/g - global replace
g/^$/d - delete all blank lines
/xxx - search down for xxx
?xxx - search up for xxx

### Search Commands

/ - RegExp search
n - repeat last search(find next)
/↑ - edit last search

### Control Commands

Ctrl-b - page up
Ctrl-f - page down
Ctrl-u - half page up
Ctrl-d - half page down

### Editing

a - append after cursor
A - append after current line
i - insert before cursor
r - replace at cursor
~ - transpose case of text at cursor
R - replace from cursor to end of new text
o - open newline after cursor
O - open newline before cursor
u - undo last action
Ctrl+R - redo last action
U - undo current line
yy - copy current line
nyy - copy n lines from current line
y/string/ copy from the cursor positon to the string's position, searching forward
y?string? copy from the string's position to the cursor, searchingbackward
p - paste
ddp - cut and paste current line
dd - delete current line
dw - delete current word
d$ - delete from cursor to end of line
D - delete from cursor to end of line
cc - change current line
cw - change current word
c$ - change from cursor to end of line
C - change from cursor to end of line
s - change current symbol
S - change current line

### Cursor Movement

h/j/k/l - move left/down/up/right
w - move forward word-by-word
b - move backward word-by-word
e - move to end of current word
W - same as w but only uses space as delimiter
B - same as b but only uses space as delimiter
E - same as e but only uses space as delimiter
} - move forward one paragraph
{ - move backward one paragraph
) - move forward one line
( - move backward one line
^ - first non-blank character
0 - start of current line
$ - end of current line
gg - top of the file
G - bottom of the file
ngg - go to line n
nG - same as ngg
% - find match of current brace in the cursor
To store a session:
To load a session while starting vim:
To load a session while in vim:
Retab one or more files from the command line
Wscript Avoid setting the file type to python by including these lines in ~/.vimrc
Clear highlighted search terms
Paste indented code into vim from another application
Redirect Terminal output to Vim
Write and quit a file
Read blocks of text from other file
This will paste line contents from line number 12 to 40 in current file
Save a file which requires sudo permission without exiting the file
Word wrap
Auto Indentation
Copy a file to current position
Move a line to another position
Indent a line
Delete a block
Set/Unset Line numbers
See/Hide special characters in vim
Must use Vim Plugins
NERDTree
Open and edit your files more efficiently. Nerd Commenter
Taglist