The vi survival guide

If, like mine, your colleagues are constantly moaning about vi when installing their machines, have them read this!

Print the essential commands shown below, stick them on top of the coffee machine and have your coworkers recite them before getting a coffee. After a week, they’ll be ready to fix any Linux box with the stock tools, even when lost in the middle of a desert (I must admit I haven’t tried the desert bit, but it should work).

Essential commands

toggles between insert and command mode
cursor left,down,up,right
insert before cursor position
add at end of line
open (insert) a line after current line
delete current line
page forward / backward
quit and save
quit without saving

Other useful commands (partial list)

word forward/backward
change word (end with ESC)
erase one character
delete 5 lines from current position
erase one word
copy current line to buffer (yank)
paste buffer after current line
display file information at bottom of screen
go to line 3
search forward for a regular expression
repeat forward search
repeat backwards search
replace word1 by word2 in the whole file with user confirmation.
replace word1 by word2 in current line with user confirmation.

5 Responses to The vi survival guide

  1. Cool, one which I use a lot is “gqap” which word-wrapped the current paragraph. In combination with :set ai , it even works on indented text, great for making things look nice.

  2. David Channon says:

    Its nice to see VI help floating around. When I was lecuring I always forced the first year students to use VI on the Unix servers for their work. Students don’t necessarily understand why your certain items are on the course. Its not always obvious but it is a part of the big picture. I view basic VI knowledge as being very important even if you don’t use it as your primary editor.

  3. I’ve been using these commands, but a bit differently :

    w : save
    q : quit
    wq : quit and save

    dd : delete line
    5dd : delete 5 lines
    cw : change word
    5cw : change 5 words
    .. and so on, nearly every command can be preceded with a number to repeat multiple times, wuite useful for example :
    yy : copy line
    5p : paste line 5 times

    “:5” : go to line number 5
    /expr : search for expression
    / : search again

    It’s nice to see how many ways there are in VI to achieve the same results.

    One very useful command is also :

    set paste

    It will activate the “paste mode”, so that if you are connecting from a terminal you can cut and paste in the terminal and avoid automatic indentation and other interpretation that would clutter your pasted code.

  4. aizatto says:

    your: d5d
    is too long
    try: 5x
    :), save 1 char

  5. amit says:

    @aizatto: 5x deletes 5 characters from current cursor position. d5d deletes 5 lines from current cursor position

%d bloggers like this: