VIM-Area auf la-familia-grande.de

Text selection

V select entire line
vselect range of text
ctrl + vselect columns
gvreselect block

Searching

/ patternsearch for pattern forwards
? patternsearch for pattern backwards
nrepeat forward search
Nrepeat backward

related variables and settings

:set ignorecasecase insensitive
:set smartcaseuse case if any caps used
:set incsearchshow match as search proceeds
:set hlsearchsearch highlighting

more cool things

*search for word currently under cursor
g*search for partial word under cursor
(repeat with n)
ctrl + o,
ctrl + i
go through jump locations
[Ishow lines with matching word under cursor

Markers

Use markers to set places you want to quickly get back to, or to specify a block of text you want to copy or cut

m a-zmark current position (use a-z)
' a-zmove to mark a-z
d ' a-zdelete from current pos to mark a-z
' a-zsame file
' A-Zbetween files

Multiple windows

:e filenameopen filename in current window
:split filenamesplit window horizontally and edit another file
:vsplit filesplit window vertically and edit another file
:sview filenamesame as split, but open file readonly
:hide, ctrl + w cclose current window
:onlykeep only the current window open
:lsshow current buffers
:b 2open buffer #2 in current window
ctrl + w nsplit window horizontally
ctrl + w vsplit window vertically
ctrl + w w move cursor to the next window (cycle)
ctrl + w arrow-upmove cursor up a window
ctrl + w _maximizie current window
ctrl + w =make all windows equal size
10 ctrl + w +increase window size by 10 lines
10 ctrl + w -decrease window size by 10 lines
ctrl + w cclose current window

Registers

When you copy and cut stuff, it gets saved to registers. You can pull stuff from those registers at a later time.

:regshow named registers and what's inside
"5ppaste content of register "5

You can also save macros in registers to apply them over and over

q a-zrecord macro and save it in register a-z
(use q again to stop recording)
@ a-zexecute macro stored in a-z
@@repeat las executed macro
5 @@repeat it 5 times
" a-z pprint macro a-z
(e.g. to edit or add it to .vimrc)
" a-z dreplace register a-z with what the cursor is on

Indenting

ctrl + t,
ctrl + d
(insert mode): indent current line forward/backward
visual > or <indent block by sw (repeat with .)

related variables and settings

:set tabstop=8tabs are at proper location
:set expandtabdon't use actual tab character (ctrl-v)
:set shiftwidth=4indenting is 4 spaces
:set autoindentturns it on
:set smartindentdoes the right thing (mostly)
:set cindentstricter rules for C programs

stop indenting when pasting text (with the mouse)

To stop indenting when pasting text with the mouse, add this to your .vimrc:
:set pastetoggle=<f11>
then hit F11 key while in insert mode (or just set :set paste)

Reformatting

V =select text, then reformat it
=will correct alignment of code
= =one line
gqreformat paragraph

related variables and settings

:set wrapmargin
:set textwidth
:set formatoptions (default "tcq")
  t - textwidth
  c - comments (plus header -- see :help comments)
  q - allow 'gq' to work
  n - numbered lists
  2 - keep 2nd line indent
  1 - single letter words on next line
  r - (in mail) comment leader after

Word & line completion

ctrl + n,
ctrl + p
next / previous word completion
(similar word in current file)
ctrl + x,
ctrl + l (ctrl + n / ctrl + p)
line completion

Edit a stream

You can take the output of any command and send it into a vim session. From there you could format it, change stuff, and then save it to a file.
find . | vim -