The vi editor
Previous  Top  Next

Throughout this course we will use the text-based VI editor to manipulate our configuration files. If you are not familiar with this editor, I will give you brief introduction so you will be able to use it without getting a heart attack.

VI has to major modes: COMMAND MODE and INSERT MODE. Since VI doesn't have a menu and fancy things like that, you can either type and modify text (INSERT MODE) or send commands such as SAVE, QUIT … (COMMAND MODE). As soon as you start VI, you are in COMMAND MODE. To change into INSERT MODE simply press I and you will see – INSERT – at the bottom. You can now type your text, change text, use the PgUp and PgDown keys and so on. Once you are done editing, you want to save your text file and quit again. To this, you first have to go back into COMMAND MODE hitting the

ESC


key. You are now in COMMAND MODE. Now type

ZZ

To save the document and go back into the command line. This is all you will need to now about VI for this guide. However, I included to most used commands to make editing a little more fun for you. But always remember, don't forget which mode you are in – you will not be able to edit text while in COMMAND MODE! Press i for INSERT MODE and ESC for COMMAND MODE.

Important commands:
ZZ<enter> 
Save and Quit
:w<enter>
Save only
:qi<enter>
Quit without saving (hooo)


dd
Delete current line
yy
Copy the current line into the default buffer
xyy
Copy lines into the default buffer
P
Insert the content of the default buffer
u
undo last command

:set number   display line numbers on the left
:set nonumber   don't display line numbers on the left

/pattern
Search for pattern


Some of you might still remember, or use, the norton commander. Redhat 7 includes a nifty tool called Midnight Commander which can be launched by typing mc wherever you are. It looks almost 100% like the good old DOS Norton Commander – but works on Linux as well! I found it to work quite reliable and I personally like the editor a lot.