Why vi? [^]
vi is the standard editor in most existing *nix environments. This means that by learning it, you make sure you will never find yourself in a spot where you cannot edit a file, because the editor is unknown to you.
vi is really very powerful, something that's difficult to see judging from its plain interface. It goes without a doubt to say, that once you get familiar with it, you may find it hard to live without it. Actually, I am using it right now, to write this page :)
So what's the big fuss with people finding it so hard to use or even not being able to use it at all? Well, I wouldn't say it's difficult to use, I'd say it's different. The whole philosophy behind vi is hard to comprehend especially by people coming from Windows (and lately also from *nix world).
vi is a console program and many people are really scared to use the console (this is one reason vi is said to be hard). Also, vi believes (well its developers) that a person should not get his hands off the keyboard for any reason while typing or editing text. This is why vi implements all its commands in such a way that they can be inserted from the keyboard, without having to use the arrow keys or the numeric keypad or anything.
Why another vi tutorial? [^]
Well, this is not really a vi tutorial, this is a very basic rescue introduction. It's meant for people who do not know vi, don't want to know vi, will never use it unless they have to (this may be the situation with Clonezilla live), but need to edit a file without going through a real tutorial.
So let's get down to it.
vi modes [^]
vi has two working modes (well, that's not entirely true, but let's just keep it simple).
- Command Mode
In this mode of operation you can insert commands (delete characters, scroll down, save file, exit the program, etc.). This is the default mode (the one that's active when vi is first launched). Anything you do starts from Command mode and ends back in Command Mode. - Input Mode
In this mode of operation all you do is insert test. This is the default mode of operation for any other editor you have ever worked with, but not with vi. In order to start typing text you have to type i or o from Command Mode in order to enter Insert Mode.
![]() |
In case you can't remember which mode you are in, just type <ESC> (that's Escape) to get back to Command Mode and take it from there. |
Although vi does provide commands for text navigation, you can still use the arrow keys and Home, End, PgUp, PgDown to move around.
vi commands [^]
vi commands are issued from the Command Mode. There are two types of commands: normal commands (which take effect as soon as you type them) and extended commands (which start with a ":" and do not take effect until <ENTER> is pressed).
The commands you will need are:
Command | Effect |
Save / Exit (Extended Commands) | |
:w | Save file |
:wq | Save file and exit |
:q | Exit the program |
:q! | Exit without saving |
:e! | Reload the file (revert to saved) |
Inserting test | |
i | Enter Insert Mode. Typing starts before current cursor position |
a | Enter Insert Mode. Typing starts after current cursor position |
o | Enter Insert Mode. Typing starts on a new line |
O | Enter Insert Mode. Typing starts on a new line above the current one |
ESC | Exit Insert Mode - enter Command Mode |
Deleting text | |
x | Delete the character under the cursor |
dd | Delete the whole line |
d^ | Delete to the beginning of the line (starting from cursor position) |
d$ | Delete to the end of the line (starting from cursor position) |
Changing test | |
cw | Change a word (starting from cursor position) |
c^ | Change text to the beginning of the line (starting from cursor position) |
c$ | Change text to the end of the line (starting from cursor position) |
Replacing test | |
r | Replace the character under cursor. Just press the desired character after r |
R | Replace text until <ESC> is pressed. Just start typing after pressing R |
Undo / Redo | |
u | Undo last action |
Ctrl-R | Redo last action |