Vim is a terminal-based text editor commonly available on Linux systems.
Installation
Section titled “Installation”On Raspberry Pi OS, install Vim using apt:
sudo apt install vimOnce installed, open a file with:
vim filenameVim uses different modes for editing and entering commands.
| Mode | What it does | How to enter |
|---|---|---|
| Normal | Navigate and run commands | Esc |
| Insert | Type and edit text | i |
| Command | Save, quit, and other file operations | : from Normal mode |
If you aren’t sure what mode you’re in, press Esc to return to Normal mode.
Editing Text
Section titled “Editing Text”From Normal mode:
| Key | Action |
|---|---|
i |
Insert text before the cursor |
u |
Undo |
Ctrl+r |
Redo |
Press Esc when you’re finished editing.
Moving Around
Section titled “Moving Around”To navigate around, use the arrow keys. Vim also provides a few useful shortcuts:
| Key | Action |
|---|---|
gg |
Go to the beginning of the file |
G |
Go to the end of the file |
0 |
Go to the beginning of the line |
$ |
Go to the end of the line |
Saving and Quitting
Section titled “Saving and Quitting”Press Esc first, then type:
| Command | Action |
|---|---|
:w |
Save |
:q |
Quit |
:wq |
Save and quit |
:q! |
Quit without saving |
Press Enter after entering the command.
Copy (Yank), Cut, and Paste
Section titled “Copy (Yank), Cut, and Paste”In Vim, copying text is called yanking, and deleting text can function like cutting, since deleted text can be pasted elsewhere.
| Key | Action |
|---|---|
yy |
Yank (copy) the current line |
dd |
Delete (cut) the current line |
p |
Paste after the cursor |
You can also combine a number with yy or dd to affect multiple lines. For example, 3yy yanks the current line and the next two lines (3 lines total), while 3dd deletes/cuts them.
Searching
Section titled “Searching”From Normal mode, type / followed by the text you want to find:
/search term
Press Enter to search.
Then use:
| Key | Action |
|---|---|
n |
Go to the next match |
N |
Go to the previous match |
TL;DR: The Bare Minimum
Section titled “TL;DR: The Bare Minimum”If you only remember a few things:
| Key / Command | Action |
|---|---|
i |
Start editing |
Esc |
Return to Normal mode |
:wq |
Save and quit |
:q! |
Quit without saving |