egginfo logo

VI Editor

block Introduction
block Starting vi
block Exiting vi
block Saving a file
block Command Mode vs Insert Mode
block Summary of Commmands

blockIntroduction

You will find vi installed on almost all *nix distributions. Although its appearance may look deceptively simple, it is in fact an extremely powerful and efficient text editor. Vi can take a some getting used to. New users generally prefer to use nano/pico or Emacs as these are easier to get to grips with quicker.

Since being first developed in the late 1970's at the University of California, Berkeley, vi remains popular today. This is despite the availability of GUI (Graphical User Interface) based editors. These are far more easier for beginners to start using without any prior knowledge.

blockStarting vi

To run vi simply type 'vi' from your shell prompt. This will load vi without a filename, which you will have to specify when you wish to save later.

$ vi

To edit an existing file just type 'vi filename'

$ vi filename

At the bottom of the screen it will tell you the filename (if specified) and the size of that file.

"filename" 12 lines, 56 characters
If the filename that was specified does not exist it would tell you its a new file as shown below. "newfile" [New file] If you did not specify a filename ("vi") the bottom of the screen will be blank.
blockExit vi

Vi has 2 modes and you need to be in command mode to exit vi. This is the default mode you will be in when you start vi. If you have left the command mode hit Esc (Escape key) to get back to command mode. If you are already in command mode, you will remain in this mode even after pressing Esc. The terminal might beep to warn you, but will not effect anything otherwise.

The command to exit is :q the colon followed by the letter q

:q

If you have made any changes to the file, vi will warn you and prevent you from exiting the editor (File modified since last complete write; write or use ! to override. ). To get around this you would issue the command :q! (colon q explanation-mark)

:q!

This will allow you to exit vi without saving any changes or modifications made to the file. Vi will not prompt you to save any modifications, so any changes you made will be lost.

blockSave & Exit

You would normally want to save any changes to a file before you exit the vi editor. The command to save the current contents of the file is :w

:w

You can combine this with the quit command by using :wq.

:wq

If you wanted to change the name of the file you wanted to save as you would use :w filename

:w newfilename

Another method of exiting vi, while saving any changes you have made is to use ZZ (capital letters). This is the equivalent of typing :wq, but is fewer movements on the keyboard.

ZZ
blockCommand Mode vs Insert Mode

Unlike other editor's, there are 2 modes in VI, the command mode and the edit mode. The command mode allows the use of multiple commands to edit or manipulate text. Most commands are 1 or 2 charachters long to allow entering with minimum keystrokes.

VI will always start out in command mode. There are a number of ways to get into insert mode, the most common of which are i and a (the difference being is that i will insert before the cursor and a after the cursor.) To get out of insert mode hit the Esc key or ^[ (ctrl-[ if your keyboard doesn't have an escape key).

By hitting Escape twice you are certain to be in command mode. Escape will also cancel the last partially typed command you had entered. You may hear a beep on some systems, which informs you that your already in command mode.

blockSummary List of Commands in Vi

^A search forward for cursor word
^B scroll up by screens
^C interrupt an operation (e.g. read, write, search)
^D scroll down by half screens (setting count)
^E scroll down by lines
^F scroll down by screens
^G file status
^H move left by characters
^J move down by lines
^L redraw screen
^M move down by lines (to first non-blank)
^N move down by lines
^P move up by lines
^R redraw screen
^T tag pop
^U half page up (set count)
^V input a literal character
^W move to next screen
^Y page up by lines
^Z suspend editor
^[ <escape> exit input mode, cancel partial commands
 ^\ switch to ex mode
^] tag push cursor word
^^ switch to previous file
   <space> move right by columns
 ! filter through command(s) to motion
 # number increment/decrement
 $ move to last column
 % move to match
 & repeat substitution
 ' move to mark (to first non-blank)
 ( move back sentence
 ) move forward sentence
 + move down by lines (to first non-blank)
 , reverse last F, f, T or t search
 - move up by lines (to first non-blank)
 . repeat the last command
 / search forward
 0 move to first character
 : ex command
 ; repeat last F, f, T or t search
 < shift lines left to motion
 > shift lines right to motion
 ? search backward
 @ execute buffer
 A append to the line
 B move back bigword
 C change to end-of-line
 D delete to end-of-line
 E move to end of bigword
 F character in line backward search
 G move to line
 H move to count lines from screen top
 I insert before first nonblank
 J join lines
 L move to screen bottom
 M move to screen middle
 N reverse last search
 O insert above line
 P insert before cursor from buffer
 Q switch to ex mode
 R replace characters
 S substitute for the line(s)
 T before character in line backward search
 U Restore the current line
 W move to next bigword
 X delete character before cursor
 Y copy line
 ZZ save file and exit
 [[ move back section
 ]] move forward section
 ^ move to first non-blank
 _ move to first non-blank
 ` move to mark
 a append after cursor
 b move back word
 c change to motion
 d delete to motion
 e move to end of word
 f character in line forward search
 h move left by columns
 i insert before cursor
 j move down by lines
 k move up by lines
 l move right by columns
 m set mark
 n repeat last search
 o append after line
 p insert after cursor from buffer
 r replace character
 s substitute character
 t before character in line forward search
 e move to end of word
 f character in line forward search
 h move left by columns
 i insert before cursor
 j move down by lines
 k move up by lines
 l move right by columns
 m set mark
 n repeat last search
 o append after line
 p insert after cursor from buffer
 r replace character
 s substitute character
 t before character in line forward search
 u undo last change
 w move to next word
 x delete character
 y copy text to motion into a cut buffer
 z reposition the screen
 { move back paragraph
 | move to column
 } move forward paragraph
 ~ reverse case
 
blueline
Home, Tcl Tutorial, Tcl/Tk Installation, Modules, Tcl Scripts, Misc Downloads, Bot Commands,
Help/FAQ, Unix Commands, Message Commands, Shell Info/Reviews, About, Contact, Links. Nano & Pico.
Bnc's, Config Generator, OnJoin/Greet Generator, Identification Generator, Botnet creation & userfile sharing
IPV6, Vi Editor, Sitemap, Knowledgebase .

Select your language:
ENGLISH/US LITHUANIAN
 
eXTReMe Tracker
Valid HTML 4.01! Valid CSS!
 
blueline
Copyright © 2008 egginfo.org - All Rights Reserved.