Development Tools

there is a text editor with text interface for BSD and Unix. The name is derived from the shortest unambiguous abbreviation of the visual command in ex (i.e. ‘vi’ )

The program was written by Bill Joy in 1976 for an early version of BSD. Subsequently, it became the de facto standard editor for Unix, undermined only by emacs.

A modal editor (like any other modal program) assigns different actions to keys depending on the mode active at the time they are pressed. The main editing modes in there are insert and command modes. In insert mode, when a key is pressed, the character typed is interpreted as belonging to the text to be entered into the editor and not as a command, as is the case in the previous mode.

Pressing the ESC key from the insertion mode allows you to return to the command mode at any time; however, to switch to the insertion mode, the character (command) i is entered: entry to the new mode is signaled by the appearance of the words – INSERT –.

Vim, or Vi IMproved, is an open source, cross-platform text editor created to provide an improved version of Vi.

From Vi, it retains the characteristic of being modal, that is, having different modes in which normal keyboard characters have text entry or command meanings. Thus, it can be used without making use of the mouse, nor the meta keys, allowing faster writing speed, at the cost of greater difficulty in use by new users. It is currently popular among programmers and users of unix-like operating systems.

gVim (or gvim or GVim) is the version of Vim with a graphical interface (and thus equipped with a normal command bar) and is available for Linux and Windows, while the corresponding version for macOS is called MacVim or Mac Vim. gVim is short for GUI Vim.

Working modes in vim

NameDescriptionhelp page
normalFor navigation and manipulation of text. start in it and go back with <ESC>:help Normal-mode
insertFor inserting new text.:help Insert-mode
visualFor navigation and manipulation of text selections.:help Visual-mode
commandFor entering editor commands.:help Command-line-mode
exoptimized for batch processing.:help Ex-mode
selectSimilar to visual but MS Windows-like.:help Select-mode

Start writing

To open vim just open a terminal, type vim followed by the name of the file you intend to edit.

$ vim /home/max/text.txt

This command will open the file ‘/home/max/text.txt’ with the vim editor. If the file is not present it will be created when vim is first saved.

When the vim document is opened, it is in command mode. If you want to edit it, you must switch to insert mode by pressing the i key. At this point we can edit the file as in a normal text editor, with the difference that we will not be able to use the mouse. To move the cursor within the document in insert mode we can use the arrows.

Once the document has been edited, we have to return to command mode to save it.

We press the ESC key. All vim commands except navigation commands within the document, are preceded by a colon (:).

The command is written at the bottom of the terminal and is executed when you press enter.

To save the document, after pressing ESC, we type:

:w

We press enter and the document will be saved.

If we intend to make other changes, we press i again.

When we are satisfied with the work done, we can save and close the document. We go into command mode and write:

:wq

Concise list of the most useful commands

Starting to write

i - to enter characters from the current position. a - to hang characters after the current position. i - to enter text at the beginning of the current line. a - to insert text at the end of the current position

Commands to save and close documents

:q - to go out :w - to save :wq - to save and exit :q! - to exit without saving

Copy/Paste

yy - copies the current row (e.g. 20yy copies 20 rows); p - paste of the line into memory;

Deleting lines and characters

x - deletes the character below the cursor; x - deletes the character to the left of the cursor; d - deletes from the cursor position at the end of the line; dd - deletes the entire line (on which the cursor is placed). ndd - deletes the n rows following the cursor (e.g., 20dd deletes 20 rows from the current one down).

Move to file

h j k l - match left down on right; in newer versions, you can use the cursor keys and don’t need to switch to command mode ^ - beginning of line; $ - end of line; g - end of the file; 1G - beginning of the file (alternatively you can use the gg command).