NOTES ON VI


1 STARTING, MODES ET PREFERENCES

1.1 Launching and Closing

vi <file>
→ launch the editor (command line);
:q!
→ quit without saving;
ZZ
→ save and quit.

1.2 Editing and Command Modes

Editing mode
→ characters that are typed constitute the text of the document;
Command mode
→ characters that are typed call different commands.

1.3 Toggling between modes

i
→ toggle to editing mode, at the current cursor position;
a
→ toggle tp editing mode, one character after the current cursor position;
o
→ toggle to editing mode by creating a blank line below the current line;
O
→ toggle to editing mode by creating a blank line above the current line;
ESC
→ exit editing mode and go to command mode.

1.4 Saving

:w
→ save the current file;
:w <file>
→ save the current file as <file> ;
C-g
→ display the name of the current file and the number of lines.

1.5 Preferences

The file ~/.vimrc contains preferences (syntax color, etc.).


2 MOVING AND SEARCHING

2.1 Moving the Cursor

C-f
→ go to the next page;
C-b
→ go to the previous page;
^
→ go to the beginning of the line;
$
→ go to the end of the line;
G
→ go to the last line;
<n>G
→ go to line <n>.

2.2 Searching

/<string>
→ search for <string> after the cursor position;
?<string>
→ recherche <string> before the cursor position;
n
→ go to the next occurence of the current search.

3 TEXT EDITING

3.1 Cutting

x
→ erase the character at the cursor position;
dw
→ erase the word at the cursor position;
D
→ erase the end of the line after the cursor;
dd
→ erase the whole line.

3.2 Copying, Pasting

yy
→ copy the current line;
p
→ paste the copied line below the current line;
P
→ paste the copied line above the current line.

3.3 Remplacing

:1,$s/<str1>/<str2>/g
→ remplace <str1> by <str2> in the whole file;
:<n>,<m>s/<str1>/<str2>/g
→ remplace <str1> by <str2> between lines <n> and <m>.

BACK

Author: F. Galliano
Last update: 05 janv. 2024