Helpful notes for VI/VIM
http://vim.wikia.com/wiki/Vim_Tips_Wiki
? http://tottinge.blogsome.com/use-vim-like-a-pro/ ?
vimdiff / gvim -d - Pretty awesome diff tool with all the features of vim. Thanks to tottinger.
- :set diffopt=filler - On by default, add spaces to keep file lines sync'd
- :set diffopt+=iwhite - Ignore white spacing
- :set diffopt+=icase - Ignore case
- :set diffopt+=horizontal - use a horizontal split rather than a vertical split
vimpager - A vim based replacement for the "man" too. Thanks to Jay K
- export MANPAGER=/usr/bin/vimmanpager in a terminal to replace "man"
- add to .bashrc for a persistent change
.vimrc - default settings for vim, put in your home dir
vim basics
- Save / Exit
- :q,:q! - quit, quit without saving
- :w - save (write)
- ZZ - save and quit
- Navigation
- j,k - down, up
- h,l - left, right
- w, b - next, previous word
- e - end of word
- 0, ^, $ - beginning of line, beginning of non whitespace, end of line
- gg, G - first line, last line
- H, M, L - Top, middle, and bottom of screen
- ctrl-d, ctrl-u - half page up, half page down
- ctrl-f, ctrl,b - page down, page up (page forward, page backward)
- % jumps to matching brackets, v% selects all text between brackets (good for shifting code)
- /foo - find "foo"
- n, N - find next, find previous
- Editing
- >>, << - shift line to the right, to the left
- x - delete character
- dd, d#[j,k] - delete current line, delete x number of lines down or up
- dw - delete word
- yy, y#[j,k] - copy (yank) current line, copy x number of lines down or up
- p - paste whatever is in buffer below cursor (yanked lines, deleted character, deleted word, etc)
- P - paste above cursor
- Viewing
- :set tabstop=4 - set the tab width to 4 spaces (but still uses a tab char)
- :set shiftwidth=4 - set the shift (>>,<<) width to 4 spaces (but still uses a tab char)
vim intermediate
- Most commands accept prefix numbers, like 5j
- :set ic / :set noic - turn off case sesitivity
- :e ++ff=unix - sets the reading/viewing file format to unix (Carriage Returns will be visible as ^M)
- :set ff=unix - removes any Carriage Returns from a file (can then be saved)
- macros - http://vim.wikia.com/wiki/Macros
- marks/buffers
- visual copying - http://vim.wikia.com/wiki/Copy,_cut_and_paste
- Ctrl-P, Ctrol-N - auto complete from the previous and next matches
- windows - ctrl-ww, ctrl-w-, ctrl-w+, ctrl-w_, ctrl-w=, ctrl-w<, ctrl-w>
- tabs