First there was ed. ed was originally written by Ken
Thompson in the early
ed is a line-based editor and part of the Portable Operating System Interface (POSIX).
To make ed more user friendly ex was created in the 1970s. ex is also line-based and like ed part of POSIX.
The vi was created on the base of ex. It got a visual mode and became a screen-oriented text editor. vi is part of POSIX, too.
Unlike vi vim isn't part of POSIX. That's why you might have to
download and install Vim before you can use
You can start Vim simply by typing:
If you want to pass some options use:
vim [options] <file>
There are many different options like '-R' to open the file readonly or
'--clean' to start vim without any personal configurations, plugins, ...
For more details refer to the man page:
man 1 vim
To open multiple files in the same window horizontally splitted use
vim -o file1 file2 file2. In order to open the files vertically splitted use
vim -O file1 file2.
If you started vim you'll ask how to terminate it. First go into the normal
mode by pressing
ESC and change with
: into the command mode.
To quit without saving enter
:q!. If you want to safe and quit enter
Like the vi vim has different modes: normal mode, insert mode, command mode, visual mode and some more.
When you started vim it will be in the normal mode (unless configured
differently). To insert text press
i (insert) to enter the insert mode.
You can now start writing your text, source code or your shopping list. If you
want to leave the insert mode press
Do you think this feels strange? Think of a painter who is watching its canvas. This is the normal mode. When the painter puts her brush on the canvas it enters the insert mode. As soon as the brush is removed from the canvas she enters the normal mode again.
i let you insert text at your cursor position. If you want to insert text
behind the cursor position press
a (append) when you're in the normal mode.
If you like to insert text at the beginning of the current line press the
I and to append text at the end of the line press the uppercase
Writing text is nice, but what to do if you want to delete some characters,
To delete the character under the cursor press
x to delete the character
before the cursor press the uppercase
If you want to delete a whole word press
dw (delete word) and for a whole
You can also delete multiple characters, words and lines by using numbers.
will delete the next 4 characters,
d5w will delete the next 5 words and
will delete the next 3 lines.
If you want to undo changes just press
u. To redo your changes which were
A very important command is the
.. It does exactly the same action again. If
d2w and you press
. it will delete another 2 words.
Increase and decrease numbers
If you want to increase a number by one put your cursor in the line with the
number. Go somewhere in front of the number and press
To decrease the number press
For increasing or decreasing by more than one put the number in front:
4Ctrl-a will increase the number by 4.
If you have a list of numbers you can mark them with
Ctrl-v and then increase
or decrease them with
From time to time I need to view binary files in hexadecimal representation in vim. The simplest way I know, is to use the external command xxd in vim:
If you changed the hexadecimal part you can turn back to the pure text representation by:
Inserting the output of an shell command like
find subdir/ -type f -name "*something*" | grep 'pattern' | sort -r | uniq in
the middle of a file is pretty easy with vim:
:r!find subdir/ -type f -name "*something*" | grep 'pattern' | sort -r | uniq