Skip to Content

Using Vi Editor

Pronco's picture

The vi editor is certainly not the easiest and most user-friendly text editor, but because of its wide availability and existence on most linux systems

The vi editor operates in two basic modes:

  1. Command mode
  2. Insert mode

when vi is started, it is in command mode. This mode allows you to enter commands to edit files or navigate your text file. However, you can only add or insert text by using the insert mode. from command mode, you can enter insert mode by typing the letter i. To return to command mode, use the Escape key

Editing text files:

  • To start the vi program, type the following at the command prompt

The filename can be a new or existing file. Remember that when you first start vi, you are initially in command mode. if you are working on a new file, you can immediately type the letter i to enter into insert mode and start adding text

If you are working on an existing file, you can use the cursor keys, or the h,j,k,l keys to navigate to where you want to begin.

You can use the CTRL-f or CTRL-b to move ahead or back a page

To insert text at an exact point, you can type the letter i for insert and start adding your text, Other options include the letter a, Which adds text next to the cursor location, and the letter o, which starts your text on the next line below the current one.

if you make a mistake while typing, you can use the backspace key to delete characters. if you want to delete characters in command mode, hit the Escape key, and then use the letter x to delete characters one at a time. If you want to delete an entire line, use the dd command. The command dw deletes only the entire word that your cursor is currently on

To save your file, hit the Escape key to enter command mode, and then type :w . To save and exit out the vi editor, use the :wq command. Or you can use an equivalent to the :wq command and type the letters ZZ in command mode to save and exit the file

If you want to exit without saving your file, use the :q command. This command asks you if you want to save the file before quitting. If you want to bypass the prompt, use the :q! command

Advantages of using vi Editor:

You can ask your self why i will use an editor, there are many easy to use editors like gedit or any other editor?

  • you should know that almost editors you know depends on the GUI libraries and XWindows. But vi is a shell based editor.
  • running vi wont need any external libraries like QT or GTK
  • vi will give you the best performance
  • you can use vi to edit your files on a remote machine through SSH.

vi editor is a MUST.

Comments

I love Vim, and anyone out

I love Vim, and anyone out there who thinks its to hard to use, it does have a built in tutor. 30 minutes on that and you'll be able to use it for most tasks. As you use it more, you will learn more features. There really are so many functions in vim, but you just learn the ones that are useful to you. I don't think anyone knows or uses %100 of its features. I use it to browse the file system and can then just edit it right there, I use it as a wiki with a plugin. When using it as a wiki any 'WikiWord will automatically create a link to that page. if the page doesn't exist it will create it for you. Then you can tab between the different wiki words and press enter to open the one of your choice. It's actually amazing to me that more people don't use it. Sure there is a steep learning curve at first, but you only have to learn it once.

_

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Dr. Radut | book