The vi EditorThe vi editor is by far one of the most used editors in the Unix community today. The vi editor has been around for a long time and continues to find new fans at an increasing rate. It's a streamlined, highly functional tool that does not require much memory. It can be said that the vi editor is Unix's most universal editor. Pronounced vee-eye, vi isn't a user-friendly editor. In fact, one of the hardest things to learn and master in Unix is file editing with the vi editor. The power of the vi editor comes from its low overhead and high functionality. To use the vi editor, you only need to open it up using the vi command. To see the vi editor in action, do the following:
To see the vi editor in action editing a preexisting file, type the following command: > vi /etc/HTMLLAB/index.htm This will open up the vi editor and the file opened will be the website's home page, index.htm. You may not have this same file; if not, use the find command to locate a file you would like to edit or view with the vi editor and open it. Now that you have a file opened, you can use a plethora of commands to edit the file. If you do have an HTML document open, you need to know how to edit HTML code to create changes on a website. If you have a file open, you may be able to read a help file for a specific application installed on your system. No matter what you choose, you will find the vi editor has a wide array of commands that can be used within it to work with the open files. One thing you have to consider is what mode the vi editor is working in. There are two modes that the vi editor operates in. The vi editor either uses command mode or insert mode.
Now that you know how vi operates, let's use it. To open a file is easy, but to actually edit it and then save it is a whole different set of tasks that we need to learn and master. You have to know how to edit files and that comes from mastering the vi editor's basic operation. Mastering the vi editor comes only from mastering the keyboard shortcuts used to operate the vi editor. Table 8.1 shows the most common manipulation keyboard shortcuts you will use.
This is not a complete list; we could probably fill this little pocket guide full of 10 minute lessons with what you can do with the vi editor from the keyboard. Perhaps it would be beneficial to visit your local library and take out a book on the vi editor to learn more ways to make it work for you, not against you. Remember that this book can only cover so much so it is important that you be careful editing files and stepping beyond the basics in the current Unix environment you are in. Set up a test lab if possible and explore from there; you will find it easier to learn and work that way. This is an example of how you can use the vi editor to edit a file named test. The two commands you need to perform this exercise are Return, which will move to a new line of text, and Esc, which is how you escape. Now, make a new file called test: > vi test This is a new file I created! Check it out, Isn't it snazzy? I thought it was By doing this, Unix will respond back to you with "test" [New file] 4 lines, 61 characters If you remember how to use the cat command, you can quickly view the contents of the new file you created call test. > cat test This is a new file I created! Check it out, Isn't it snazzy? I thought it was As you can see, the vi editor can be helpful to you for editing a plethora of different file types. Make sure you remember that learning the vi editor takes a lot of time and practice. I hope that you continue to use it; if not, then maybe you might like to try emacs. |