vi-editor VI Editor (vee-eye, read vi ai) is a text based editor used by many users of UNIX / LINUX.  Editor was first developed by William (Bill) Joy when he became a graduate student at the University of California at Berkeley in 1976.

Use VI editor is a little bit difficult for users.  Due to the unavailability of a menu that provides instructions to perform a command.  But if you want to master Linux, of course, be a little familiar with this editor.  The commands in this editor must be memorized syntax.

VI editor has two modes, :
1.  Command mode (command mode) is used to give commands to edit text.
2.  Insert mode (insert mode) is used to perform text typing.

The first time you start the VI editor, by default we find the Command mode (command mode).  To enable us to live insert mode to type the letter i.  When we press the [Escape], then we will return to command mode.  In addition to our letter i can also press the button insert.

To start the VI editor you can type the command:

#> Vi namafile.txt

If the file namafile.txt found, then the editor will open the document.  But if not found, then the VI editor will create a new file with that name (namafile.txt) if it is stored.  For that not to mis-typed the name of a file to be edited.

The commands are valid in command mode:

1.  Cursor Navigation

     * L, right arrow or space: to shift to the right 1 character
     * H or left arrow key: to shift to the left 1 character
     * J or down arrows: to scroll down 1 line
     * K or up arrow: to shift up 1 line
     *: 0 or 1-Shift-G: to move into the first row
     *: $: To move to the last row
     * NG: to move to the row to the n
     * 0: to move the line beginning
     * $: To move end of line
     * ^ F: move down one full screen.
     * ^ B: move one screen full up.
     * ^ D: move half a screen down.
     * ^ U: move half a screen to the top.
     * ^ W: move one word forward.
     * ^ B: to move one word backward.

       ^ Sign is a sign of the Ctrl key, ^ F means that you must press the Ctrl key together with the key of F.

2.  Deleting Text

     * X: used to erase one character at the cursor position
     * X: used to erase one character to the left of the cursor position
     * Dw: used to delete a word at the cursor position right
     * Db: used to delete a word at the left of the cursor position
     * Dd: used to delete a row at the cursor position
     * D [Enter] key: to delete two lines, lines at the cursor position and the next line
     * D0: to remove from the start line until just before the cursor position
     * DL: to delete from the cursor position until the end of the display on screen
     * D $: used to erase from the cursor position to end of line
     * DG: used to erase from the cursor position to end of line in the file
     * D ^: Deletes from the cursor position until the beginning of the line of the file
     * 3dd: Delete three rows from the cursor position down

3.  Copy and Paste Text

To perform the copy and paste commands we must consider the following steps:

     * Place cursor on row position to be copied.
     * Example if you want to copy 5 lines, use the command 5yy (press the number 5 followed by the y-2x)
     * Then place the cursor on the place to be in the insert out and then press p to paste.

yy: to copy a single line
YW: to copy a word to the right of the cursor position
Yb: to copy a word to the left of the cursor position
y0: to copy from the start line until just before the cursor position
YL: to copy from cursor position until the end of the display on screen
y $: to copy from cursor position to end of line
YG: to copy from cursor position until the end of the line in the file
y): to copy from the position of the cursor to the beginning of a sentence
y (: to copy from cursor position to end of sentence

p: for pasting text

Example: 3yw command means copy 3 words from the right cursor

4.  Moving Text

To move the text we can follow these steps:

     * Place the cursor at the position of the line that will be cut.
     * Example if you want to move 5 lines, use the command 5dd (press the number 5 followed by the d as much as 2x)
     * Then place the cursor on the new site and then press p to paste.

5.  Canceling Changes
If we make any typographical or accidentally delete, we can fix it by using the commands u or U.

     * U command used to undo the last change made by user
     * U command is used to undo all changes on one line.

6.  Looking for Strings and Characters

VI editor can do a search on the string and character.  To search string, the command used is the command / and?.  At the second command is used, the command typed will appear at the bottom of the screen, where you type the string that you want to search.

Example: Suppose we want to find words <VirtualHost>, we just type the command / <VirtualHost>.

What is the difference between / and?  The second principle is the same command, which differ only in the direction of the search to be performed.  Command / looking downward, while the command?  looking towards the top of the file.

N and N commands are used to continue the search process earlier.  N command will search in the same direction, while the N command will search in the opposite direction.  To perform a search of a particular word, can be used a command like the following example:

/ \ <host\>

means that this command will only search for the string with the value of the host alone, said VirtualHost will be ignored.

7.  Out of the VI Editor

To get out of VI, then you should first go to command mode by pressing the ESC key on the keyboard or can be by pressing "Control [".  Well after being in the COMMAND MODE type: q to exit VIM without a save, if the file was opened has been modified by you then VIM will not let you out and to ignore this warning then it using: q!  to get out of the VIM and ignore any changes to the file.

8.  Save job

If want to save files that are already in the fox, simply type: w and press enter.  If you want to save the files being opened by another name then type: w namafile_new and press enter the file will be saved into namafile_new.

9.  Other Additional Commands

There are still many VI editor commands that can be used, including:

     * : R nama_file: is the command to paste the contents of the file filename into the file we are open
     * : Q: used to exit the VI Editor
     * : W: used to store files
     * :! Ls: used to list the contents of current directory then (without exiting the editor VI).  To return to the VI editor, press Enter.
     * : Sh: is the command to leave the VI editor for a while to do some other commands in the shell.  Use ctrl-d to return to the editor VI.

All orders VI above can be combined with existing orders, for example the command: wq mean we give the command to save a file and then immediately exit the editor VI.

0 comments