Vim is a text editor. It is in the top 5 of the most popular text editors. Some of its advantages are:
- Runs inside terminal, so it is easy to use on remote servers with ssh.
- Widely available on Linux distributions. If you ssh somewhere, Vim is the probably the most likely terminal text editor to be installed.
This article focuses on Vim basics and the use case where you are in a terminal in the ssh session and want to quickly edit/explore files within the terminal.
Install
Open file in Vim
Basic usage
Unlike more traditional text editors, where if you start typing the letters will be inserted at the place of your cursor, Vim works little differently. In Vim you have modes and commands, the default mode is for text navigation or manipulation, and letters on your keyboard are shortcuts for things like cut, paste, mode change or save file. So if you want to select text, you enter Visual
mode, if you want to insert text, you enter Insert
mode and so on.
Modes & Commands
Mode name | Key | Description |
---|
Normal | Esc | For navigation and manipulation of text. The default mode. You can usually get back to this mode with Esc . |
Insert | Insert or i | For inserting text. |
Visual | v | Text selections. |
Visual Line | V | Selection of whole lines. |
Command | : | For entering commands like search, save file or exit Vim. |
Normal mode
Command | Key | Abbreviation |
---|
Undo | u | undo |
Redo | Ctrl + r | redo |
Cut (delete) line | d and d | delete |
Scroll up/down whole page | Ctrl + f /b | forward/back |
Scroll up/down half page | Ctrl + u /d | up/down |
Move to the start of the document | g and g | beggining |
Move to the end of the document | G | |
Visual mode
Command | Key | Abbreviation |
---|
Copy | y | yank |
Paste | p | paste |
Cut (delete) selection | d | delete |
Scroll up/down whole page | Ctrl + f /b | forward/back |
Scroll up/down half page | Ctrl + u /d | up/down |
Move to the start of the document | g and g | beggining |
Move to the end of the document | G | |
Command mode
Command | Key | Abbreviation |
---|
Save file | w | write |
Quit Vim | q | quit |
Force quit Vim (drop unsaved changes) | q! | quit |
Save file and quit Vim | wq | write + quit |
Search | /searched term | |
Search – next item | n | next |
Search – previous item | N | |