Methods of payment Abuse

What you need to know to work at Vi

10.01.2025, 19:36

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.

How Vi differs from Vim

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.

Why is it worth learning Vi?

Here are five reasons why I recommend learning Vi and Vim:

  1. Vi is always available, as it is required by the POSIX standard.

  2. Vi/Vim is well documented. The editor has its own user manual - just type :h in command mode .

  3. Vi/Vim has many plugins available. Most of them can be found at vimawesome.com, one of the most popular places to download them.

  4. 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.

Starting Vi

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 modes

Vi works in two different modes:

  1. Command mode: used for navigation, copy, paste.

  2. Paste mode: this is where you directly enter text.

Using normal mode

? 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>.

1. Move commands:

  • h - left.

  • j - down.

  • k - up.

  • l - right.

2. Deletion commands:

  • x - deletes the character under the cursor.

  • dd - deletes the current line.

3. Copy and paste:

  • y - copy selected text.

  • yy - copy the current line.

  • p - paste text after the cursor.

Command mode

? 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.

Insertion mode

? 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.

Visual mode (only in Vim)

? In this mode you can highlight text, which is especially useful for working with large paragraphs.

  • v - characters.

  • V - lines.

  • Ctrl+V - block mode.

Output

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.