Getting Started With Vim (vi improved)

·

2 min read

Getting Started With Vim (vi improved)

Vi is a screen-oriented text editor created for the Unix operating system.

Basic Vi commands

There are two modes when in Vi

  • Command mode( press ":<command>" )

  • Insert mode( press "i" then Esc to enter command mode)

To start ;

To use vi on a file, type in the vi file name. 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.

To exit ;

Usually, the new or modified file is saved when you leave vi. However, it is also possible to quit vi without saving the file.

  1. :x (Enter) - quit vi, writing out modified file to filename in the original invocation

  2. :wq (Enter) - quit vi, writing out modified file to filename in the original invocation

  3. :q (Enter) - quit/exit vi

  4. :q! (Enter) - quit vi even though the latest changes have not been saved for this vi call

Inserting Text

The following commands put the vi into insert mode, thus, the <Esc> key must be pressed to terminate the entry of text and to put the vi editor back into command mode.

  1. "i" - insert text before the cursor until {Esc} is hit

  2. "I" - insert text at beginning of the current line, until {Esc} is hit

  3. "a" - append text after the cursor, until {Esc} is hit

  4. "A" - append text to the end of the current line, until {Esc} is hit

  5. "o" - open and put text in a new line below the current line, until {Esc} is hit

  6. "O" - open and put text in a new line above the current line, until {Esc} is hit

Cutting and Pasting Text

  1. "yy" (yank)- copy the current line into the buffer

  2. "p" - paste the line(s) in the buffer into the text after the current line

Saving and Reading files

  1. ":r" <filename> (Enter) - read the filename and insert it after the current line
    (the line with cursor)

  2. ":w" - write current contents to file named in original vi call

N/B; Still being written.