Skip to Content

Revision of Using the Vi Editor from Fri, 09/07/2004 - 3:03am

The revisions let you track differences between multiple versions of a post.

Pronco's picture

Linux Administrators are constantly changing the configuration files of their system services and applications to enable new services or to make them run more efficiently. All configuration files in Unix are simple text files, but in order to edit them, you need a text editor. A wide variety of editors are available for Linux and Unix. Some of the most popular editors include Emacs and Pico. Although each person has his or her own favorite editor, only the vi editor comes by default with every version of Unix

The vi editor is certainly not the easiest and most user-friendly text editor, but because of its wide availability and existence on most Unix systems, it is extermely important that every Linux System Administrators know how to use it

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


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