vi editor

To Start vi: To use vi on a file, type in vi filename. If the file named filename exists, then the first page (or screen) of the file will be displayed; if the file does not exist, then an empty file and screen are created into which you may enter text.

vi  filename – edit filename starting at line 1

vi -r filename – recover filename that was being edited when system crashed

To Exit vi Usually the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file. Note: The cursor moves to bottom of screen whenever a colon (:) is typed. This type of command is completed by hitting the (or ) key.

😡  – quit vi, writing out modified file to file named in original invocation

:wq – quit vi, writing out modified file to file named in original invocation

:q –  quit (or exit) vi

:q! –  quit vi even though latest changes have not been saved for this vi call

Inserting or Adding Text

The following commands allow you to insert and add text. Each of these commands puts the vi editor into insert mode; thus, the key must be pressed to terminate the entry of text and to put the vi editor back into command mode.

i –  insert text before cursor, until hit

I –  insert text at beginning of current line, until hit

a – append text after cursor, until hit

A – append text to end of current line, until hit

o – open and put text in a new line below current line, until hit

O – open and put text in a new line above current line, until hit

Changing Text The following commands allow you to modify text.

r – replace single character under cursor (no needed)

R – replace characters, starting with current cursor position, until hit

cw – change the current word with new text, starting with the character under cursor, until hit

cNw -change N words beginning with character under cursor, until hit;

C – change (replace) the characters in the current line, until hit

cc – change (replace) the entire current line, stopping when is hit

Ncc or cNc -change (replace) the next N lines, starting with the current line, stopping when is hit

Deleting Text The following commands allow you to delete text.

x–  delete single character under cursor

Nx –  delete N characters, starting with character under cursor

dw – delete the single word beginning with character under cursor

dNw – delete N words beginning with character under cursor;

D –  delete the remainder of the line, starting with current cursor position

dd – delete entire current line

Ndd or dNd – delete N lines, beginning with

Leave a Reply