vi – Linux/unix editor




This is one the most important tools to know and could either cause alot of headaches and save you from them. This is most common text editor in Linux and UNIX. People tend to love it or hate it. Either way, it’s nearly always there in any *nix implementation and just by memorising a few commands you can be up and running with it. Just remember if you get stuck type :q! to exit without saving.

To open a file in vi type:
vi filename

The first thing that throws you is that to enter text into your file, you need to press “i” for Insert mode. You can then enter your text just as any other text editor. When you are done with text entering, just press the Escape (Esc) key to come out of insert mode. If you are happy with your file, then we need to Write & Quit (wq). To enter commands in this command line editor, rather than having menus, we have a command prompt in the application. To reach the vi command prompt, simply enter “:” - the colon character which will automatically place your cursor at the bottom of the session. Here you can enter the “wq” command to write and quit the editor. That’s it!

Here is a summary of the vi commands

i Changes to insert mode where you can edit the text
:wq Write the file and quit the editor
:q! Quit the editor without saving changes
Shift ZZ Quit the editor and save any changes made - just a fast way of doing “:wq”
esc key Exits the current mode, e.g. out of insert mode back to view mode.
/ search - if you entered /failed then the cursor would move to the first instance of “failed in the text
$ Jumps to the end of a file
yy copy - it’s y for yank!
dd delete a line (cut) if you precede this with a number e.g. 8dd, then it would delete 8 lines
p paste
%s/old/new/g substitute any occurrences of the world “old” with the world “new”



You can leave a response, or trackback from your own site.


Further Reading
    None Found




Leave a Reply

Anti-Spam Quiz:

Twitter Delicious Facebook Digg Stumbleupon Favorites More
334 queries in 5.970 seconds.