One of the most important tools of a unix administrator is ability to use a text editor. Perhaps the most popular text editor available on unix systems is the vi improved editor, or simply vim.
Here is my cheat sheet. When I find useful commands that reduce the time that I spend editing files (which can be a day long process) I put things here so that I can remember them later. The functions here are what I find highly useful for good editing. Having the ability to reduce the work involved in making many changes at once is advantageous, so here is my over view of the things which I think benefit the most when using vim.
^c indicates a control character for letter c.
commands
The commands that I think are perhaps the most important of are the following
command
action/purpose
{,}
moves to the beginning or end of paragraph at cursor
(,)
moves to the beginning or end of sentence
m
sets a bookmark in a-z and A-Z slots (help m)
'
jumps to bookmark in slot a-z and A-Z (help m)
gg
jumps to start of document
G or :$
jumps to end of document
:n
jumps to line n
z=
suggest spelling alternatives
*,#
go to matching word under cursor. this is useful for jumping to a function that you're calling (* = forward, # = reverse )
gg=G
apply tabulation rules to the current file
ga
shows the hex, decimal and ordinal values of the character under cursor
ctrl-a/ctrl-x
adds/subtracts to/from decimal under cursor
J
joins this line in the next (keeps inserts a space character between join
^f, ^b
go forward or backwards by a page
1,$!grep something
run the grep command on the full buffer (1,$)
visual mode
command
action/purpose
ab/aB
select () or {}
:
perform operation on block
:'<,'>s/foo/bar/g
perform regular expression subsitution on block
gu / gU
switches the case of the visual block depending on the case of u
g?
rot 13 the block
^v
visual block selection, rather than selecting by line this will select by rectangle
config
The environment for vim that I find the most convenient can simply be stored in a text file in your home directory named ~/.vimrc.
command
action/purpose
set spell
enables spell checker, right click, or z= to suggest alternatives
set number
show line numbers
set autoindent
automatically tab on code blocks
set ts=8
sets the tab stops to 8 character spaces
set sw=8
sets the autowrap to 8 characters
syntax enable
automatically highlight code keywords
set linebreak
automatically wrap whole words. this can be used rather than set line width
set fileformat=dos/unix/mac
sets the line breaks when saving
for code
command
action/purpose
]p
paste, but indent at the same time
%
go to matching (, {, [ etc
gd
go to definition or declaration
K
go to man page for the word under cursor
:mksession, vim -S Session.vim
save session and open the saved session
video links
These pages contain links to various external sites that have vim videos. These videos are for educational purposes and might be live demonstrations or talks describing how vim works.