vim -tutorial -2

Vim is a text-editor for the console, with 2 modes.

$ vim file.txt

When you start vim, you are not initially in the edit mode.

The easiest way to enter the edit mode at the beginning is to press the Insert key.

some text
~
~
~
-- INSERT --

You can also press the key i to enter the edit mode, which is easier to access on the keyboard.

In edit mode, you can edit the content, with all the keys of your keyboard.

This text-content is in the utf-8 format, by default.

Exit the edit mode with the Escape-key, and you will be in the command-mode again, like at the beginning.

In command-mode, you can do copy-paste commands for example.

These commands are launched by keys that usually represent the initial letter from the name of this command.

You can move the cursor with the arrow-keys, or some commands, to navigate into the text, or the source-code.

In command-mode, you can start to high-light some text by pressing the v-key, which will start the visual-mode.

some text
~
~
~
-- VISUAL --

Then move with the arrows until your destination, and press the command y (yank), which will place the text into the copy-buffer.

Move again with the arrows, and place this text at the position of the cursor with p.

Some commands to navigate, e to jump until the end of the next word, gg to jump until the beginning of the file, and G at the end.

At the end, you can type :w to save, and :q, to quit (in "command-mode").


We already saw that you can enter the edit-mode, with i, but there are also other keys to do so, and position the cursor in different way.

I, will enter the edit-mode and position the cursor at the beginning of the current-line.

O, will start a new line above the current-line.

o, will start a new line under the current-line.

a, is similar than i, but will start editing after the current position of the cursor.

A, will start editing at the end of the line, where the cursor is currently positioned.

A and a, stand for append.


deleting. You can delete the content of the current line, from the current position of the cursor, until the end of the current line, with: d $. d being the command to delete, and $ being the command to jump until the end of the current line.

More commands to jump in command mode: { and }, to jump respectively until the beginning or the end of the current paragraph (or block of code, if you're coding).

b, to jump until the beginning of the current word, or until the beginning of the previous word, if you are already at the beginning of a word.


With d $, you delete the content of the current line until its end, and stay in command-mode, but with c $, you will do the same, but you will enter the edit-mode in stead.


The command u, is for undo. And Ctrl+R for redo.


Ctrl+v, vertical visual-mode, then move the cursor w/ the arrow-keys,

Shift+v, line visual-mode, then move the selection in a similar way.

some text
some text
some text
~
~
~
-- VISUAL BLOCK --
some text
some text
some text
~
~
~
-- VISUAL LINE --

After a high-lightning with one of the visual-commands, you can either copying it w/ y (yank), or delete it w/ d so that you can eventualy paste it in another place w/ p.


d %, delete until the matching < >, ( ), [] or {}, and place the result into the copy-buffer, so that you can paste it in another place w/ p.

P is similar than p, but will paste just before the cursor.


You can edit several-files with:

$ vim file-1.txt file-2.txt

And then navigate from one to the other one with the keys: :n, :N.


In command-mode, you can make a "grep" with: /word. It will search the next occurence of the word.