Basics
VI has two basic modes:
All actions around VI are taken from command mode. To enter command mode hit ESC key. As response the status bar indicates an empty state. To execute a command it should be initilized by a colon : followed by the command q (in this case quit) and finished by hitting the enter/return key CR.
E.g. :q Enter
In this mode all key strokes are inserted into the document, like in common GUI editors. To get from command mode to insert mode the user has to hit i. The status bar indicates this state with -- INSERT --.
Switch to command mode
ESC
Movement
Most of the movement in the document is being done from command mode. In insert mode the user can navigate via the arrow keys.
Command | Description |
---|---|
|
Move one word forward |
|
Move one word back |
|
Move to start of the current line |
|
Move to end of current line |
ctrl + u (holding ctrl down) |
Scroll up |
ctrl + d (holding ctrl down) |
Scroll down |
Command | Description |
---|---|
|
Go to first line |
|
Go to last line |
|
Go to line 42 |
Switch to edit/insert mode
Command | Description |
---|---|
|
Insert before cursor |
|
Insert before line |
|
Append after cursor |
|
Append after line |
|
Start new line after current line |
|
Start new line before current line |
Delete
Command | Description |
---|---|
|
Delete a character |
|
Delete a word |
|
Delete a line |
|
Delete 7 lines |
Copy and Paste
-
Copy the current line with yy
-
Move with the cursor to the wanted position
-
Paste with p command
Command | Description |
---|---|
|
Copy current word, beginning from cursor position |
|
Copy current line |
|
Copy 7 lines |
|
Paste |
|
Duplicate current line |
|
Move line up |
|
Move line down |
Search
Command | Description |
---|---|
|
Search for the pattern foo forward |
|
Search for the pattern foo backward |
|
Search for next instance |
|
Search for next instance in the opposite direction |
|
Search for the pattern foo forward and ignore case |
|
Search for the exact string My Exact Search String forward |
|
Search for the exact string Kacper Bak OR for the exact string kacper bak forward |
|
Case insensitive search and replace |
Working with multiple files
Command | Description |
---|---|
|
Open or edit file inside VI |
|
Close file inside VI |
|
Display all open files |
|
Switch to open file |
Common usage
Command | Description |
---|---|
|
trigger VI Autocompletion |
|
Repeat last action with one key stroke |
|
Undo last action |
Settings
To configure VI use the keyword set.
The following command disables the line numbers e.g.: set nonumber
Command | Description | Example |
---|---|---|
|
Enables/Disables line numbers |
|
|
Use syntax highlighting of a specific language |
|
Sources
-
Plötner, Wenzel - Linux das distributionsunabhängige Handbuch, ISBN 3-89842-677-7