Editing with Vi

What is Vi?

Vi is to Unix/Linux what Notepad is to Microsoft Windows. Vi is the default text editor used with Unix/Linux systems. The name Vi is short for the term Visual editor. Because Vi was made for Unix/Linux systems, it stands to reason that it would use a command line user interface.

Modes:

Vi has two modes:

  1. Command mode – Using commands to manipulate the text
  2. Insert mode – Entering text as you would any other text editor

Editing in Command Mode:

You can use the j, k, h, l keys to move curser down, up, left, right respectively. Or, you can just use the arrows on the number pad.

You have no mouse action using Vi, so here some moves to keep in mind.

$ - moves the curser to the end of line your curser is on
w – moves the curser to the beginning of the next word
b – moves the curser to the beginning of the previous word
/ - Find command (used to find whatever letters or numbers follow)

Let's get started with some basic editing

vitut_1.jpg

I want to change the word bright in the first sentence to fine. So, I will enter /br to find the first word that starts with br.

vitut_2.jpg

Now that I have the word I want to change, I will use the cw command to change the bright to fine.

vitut_3.jpg

Keep in mind that it will put you into insert mode, so, you will need to press Esc to go back to Command mode.

On line 7 lieis should be lie is. Notice there are two blank lines before the text at the top, so it is actually line 9. 9G command will get us to the right line.

vitut_4.jpg

You can press the w key to advance the curser one word at a time, or you can advance by a number of words like 7w.

vitut_5.jpg

From here you can use the cw command to change the the word lieis to lie is, or advance the curser with the l key, or right arrow key, to set the curser on i in is, press the i key to enter the insert mode and press the space bar. Remember to press Esc to exit the insert mode.

vitut_5.jpg

When you are done editing, don’t for get to save your work. There are several ways, but I usually use the :x which saves the file and closes Vi.

You can view my other articles at sharkness

Unix/Linux | Open Source | Software | How To


QR Code
QR Code editing_with_vi (generated for current page)