Friday, September 13, 2013

Vi Editor Tutorial Cheat Sheet

Starting vi


To start vi at the prompt enter:

[root@ts3 ~]#vi filename

If the file does not exist vi will create it for you.

Command Mode and Input Mode


When you first open a file with vi it takes you to command mode. To get to input mode type "i" :

i

To return to command mode press the ESC key:

[Esc]

Deleting Text


 To delete text using the following commands you have to be in command mode:

Command  Function
x Delete the character that the cursor is on
[Shift] d Delete from the cursor to the end of the line.

db
Delete from the cursor to the beginning of the current word
de Delete from the cursor to the end of the current word
dd Delete the current line that the cursor is on
d [Shift] g Delete the current line that the cursor is on to the bottom of the file


Undo



To undo changes or line deletions you have to be in command mode and type the following:

u

Goto



to go to a particular line a file go to command mode and type :linenumber :

:14

You can also type in the line number followed by:

[Shift] g

To see what line you are on:

 [Ctrl] [Shift] g

To display all the line numbers:

:set number

To go to a particular line in a file while opening a file with vi:

[root@ts3 ~]#vi  +45 filename

To go to a particular pattern in a file while opening a file with vi:

[root@ts3 ~]#vi  +/pattern filename

Search



To search forward for some text, use the / (forward slash) command:

/pattern

To look for the next occurrence of that pattern:

n

To look for the previous occurence of that pattern:

[Shift] n

To find and replace that pattern:  


Saving Work



To save changes go to command mode and type:

:w

To save a file with a different filename:

:w filename

To save and exit:

:wq

To exit without saving:

:q!

1 comment:

  1. The theme of the sport is an journey into the paranormal world of historical Egypt. Excellent graphics thecasinosource.com and superb designs combine nicely with the sound results to make a jazzy and thrilling recreation. The recreation also has the bonus characteristic which gives you an emblem chosen at random which acts as a sort of joker during the lifetime of the bonus.

    ReplyDelete