Saturday, April 24, 2010

Working with Vim

It is convenient to make vi alias for vim:
apt-get install vim less
update-alternatives --set vi /usr/bin/vim.basic
update-alternatives --set editor /usr/bin/vim.basic


i - opens insert mode for editing, inserts text after the current cursor position
esc - returns to command mode
a - opens insert mode for editing, inserts text at the current cursor position
:w - writes changes
:wa - writes all changes
:x or ZZ - writes and quits
:q! or ZQ - quits without saving changes
:xa - writes and quits all windows

Text Manipulation

u - undo
v - enters visual mode to mark a block on which you can use commands
d - deletes the current selection
y - yanks (copies) the current selection
p - paste
gq - reformat paragraph

Moving around

gg - top of the file
G - bottom of the file
/text - search forward
n - next match
N - previous match
?text - search backward
:%s/old/new/g - replace old with new globally


^ws - horizontal split
^wv - vertical split*
^wc - close current window
^w up arrow - move cursor up a window
^w_ - maximize current window
^w= - make all equal size


zo - open
zc - close
* - if some commands for any reason doesn't work for you, most likely you are using vi or somewhat cut version of vim. See vim cheat sheet.

No comments :

Post a Comment