VI is a powerful console text editor. It is deservedly one of the most popular tools in Unix systems. And all thanks to its speed and a huge number of text manipulation features. However, it can be a bit difficult to master. That's why we have collected the main commands of Vi editor in this article.
Vim includes additional features such as syntax highlighting, mouse support, and more. The basic commands and keyboard shortcuts remain the same in both VI and Vim. Therefore, by learning Vi, you will automatically learn the basics of Vim and its other derivatives.
Here are five reasons why I recommend learning Vi and Vim:
Vi is always available, as it is required by the POSIX standard.
Vi/Vim is well documented. The editor has its own user manual - just type :h in command mode .
Vi/Vim has many plugins available. Most of them can be found at vimawesome.com, one of the most popular places to download them.
The editor consumes a minimal amount of resources. This makes Vi ideal for a wide variety of tasks. And software development is just one of them! For example, you can write very long texts, up to novels, in Vi without any problems. Other text editors, especially GUI applications, can break and crash from such loads.
Type the command to start the program:
vi
You can also open a file by specifying its name. If the file exists, it will open for editing, and if not, a new one will be created:
vi your_file.txt
Vi works in two different modes:
Command mode: used for navigation, copy, paste.
Paste mode: this is where you directly enter text.
? This mode is enabled by default when you open VI/Vim.
It is used for actions such as moving through text, copying, pasting, deleting, replacing text (but not editing it). To return to this mode, press <Esc>.
h
- left.
j
- down.
k
- up.
l
- right.
x
- deletes the character under the cursor.
dd
- deletes the current line.
y
- copy selected text.
yy
- copy the current line.
p
- paste text after the cursor.? This mode is activated in normal mode by pressing :.
Examples of commands:
:wq
- save changes and exit.
:q!
- to exit without saving.
:h
- help.
:/string
- search for string
.
:%s/foo/bar/g
- replace all occurrences of "foo" with "bar" in the whole document.
? This mode is used for text editing.
You can switch to it by pressing:
i
- insert text in front of the cursor.
I
- insert text at the beginning of the line.
a
- add text after the cursor.
A
- add text to the end of the line.
? In this mode you can highlight text, which is especially useful for working with large paragraphs.
v
- characters.
V
- lines.
Ctrl+V
- block mode.
Vi/Vim is present in almost all Unix-like systems. Spending a little time to master it will give you one of the best text editors.