Greg's Blog

helping me remember what I figure out

Basic Vi Editing

| Comments

This document will introduce some of the basic vi editing concepts. First off what is vi? Well it’s the built-in text editor that you find on most Unix boxes (including Linux). You start it up by typing the following command:

[code]vi myFileName[/code]

myFileName is either an existing file or a new file that you wish to create. OK so far so good. A word of warning I found navigating around text initially a real pain. How do you enter text? Well hit the i key, which stands for… you guessed it insert. You are know in insert mode and can insert text into that file. To stop entering text press CTRL+[

Next let’s delete some text that you have entered. There are two ways of doing this. If you want to delete just portions of the text, e.g. a word, first make sure that you are not in the Insert mode (CTRL+[), move to the first letter of the word you wish to delete and pressn x. This should have deleted the first letter. Keep pressing x until you have completely removed the word you wanted to delete.

What if you want to delete a complete line type dd. This removes the entire line and places it into the buffer. I guess this command is similar to the cut command you would use under windows. So can you paste it back in? Of course you can. Just press p at the appropriate location and the line should reappear.

Next I will show you how to quit the editor without saving. To do this make sure again you are in no editing mode (CTRL+[) and type: :q!. This should take you back to the command prompt or shell. To quit and save, type: :wq!. Again make sure that you are not in edit mode first.

Well that’s about the extent of my knowledge on vi editing as it is all I need to know. However if I get stuck or should you want to learn more about vi editing then I can seriously recommend this book: Learning the vi Editor from O’Reilly & Associates, Inc. As with most books from O’Reilly it’s clear, concise and very informative.