# How to use vim

#### Installation

Example of installation on Ubuntu.

```shell
apt-get update
apt-get install vim
```

#### Open a file

<span style="color: rgb(0, 0, 0);">If your user does not have sufficient permissions, you will need to prefix the command with `**sudo**`.</span>

```shell
sudo vim file.txt
```

#### Modes in vim

Once you’re in Vim, you’ll be in **normal mode**, which allows you to view and search through the file.

[![image.png](https://bookstack.soffid.com/uploads/images/gallery/2026-07/scaled-1680-/rlSrpTpIpzaw9TuL-image.png)](https://bookstack.soffid.com/uploads/images/gallery/2026-07/rlSrpTpIpzaw9TuL-image.png)

To edit the file, you need to be in **insert mode**.

- Use the '**i' key**, to enable it.
- Use the **Escape key** to exit**.**

[![image.png](https://bookstack.soffid.com/uploads/images/gallery/2026-07/scaled-1680-/EErVwIL8zxg3AKDc-image.png)](https://bookstack.soffid.com/uploads/images/gallery/2026-07/EErVwIL8zxg3AKDc-image.png)

Finally, to use commands, there is **command mode**, which is activated by pressing the Escape key.

- Use the '**:' key**, to enable it.
- Use the **Enter key** to apply it**.**

[![image.png](https://bookstack.soffid.com/uploads/images/gallery/2026-07/scaled-1680-/VAFEGN94Xq0tBZac-image.png)](https://bookstack.soffid.com/uploads/images/gallery/2026-07/VAFEGN94Xq0tBZac-image.png)

#### Commands

From **normal mode** (press **Esc** just in case), press '**:' key** to move to the bottom of the screen and use one of these commands, followed by **Enter**.

<table border="1" id="bkmrk-command-action-%3Aw-sa" style="border-collapse: collapse; width: 100%; height: 148.984px;"><colgroup><col style="width: 25.0596%;"></col><col style="width: 75.0596%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Command**</td><td style="height: 29.7969px;">**Action**</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">:w</td><td style="height: 29.7969px;">Save (write) without exiting.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">:q</td><td style="height: 29.7969px;">Exit (quit). Vim will not let you exit if there are unsaved changes.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">:wq</td><td style="height: 29.7969px;">Save and exit.</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">:q!</td><td style="height: 29.7969px;">Forcefully exit without saving changes.</td></tr></tbody></table>

#### Navigation

From **normal mode.**

<table border="1" id="bkmrk-command-action-arrow" style="border-collapse: collapse; width: 100%; height: 148.984px;"><colgroup><col style="width: 25.0596%;"></col><col style="width: 75.0596%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Command**</td><td style="height: 29.7969px;">**Action**</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">arrow left or h</td><td style="height: 29.7969px;">Left</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">arrow down or j</td><td style="height: 29.7969px;">Down</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">arrow up or k</td><td style="height: 29.7969px;">Up</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">arrow right or l</td><td style="height: 29.7969px;">Right</td></tr></tbody></table>

#### Quick edit

From **normal mode.**

<table border="1" id="bkmrk-command-action-x-del" style="border-collapse: collapse; width: 100%; height: 148.984px;"><colgroup><col style="width: 25.0596%;"></col><col style="width: 75.0596%;"></col></colgroup><tbody><tr style="height: 29.7969px;"><td style="height: 29.7969px;">**Command**</td><td style="height: 29.7969px;">**Action**</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">x</td><td style="height: 29.7969px;">Deletes the character under the cursor (like the Delete key).</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">dd</td><td style="height: 29.7969px;">Remove and cut the full line</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">u</td><td style="height: 29.7969px;">Undo</td></tr><tr style="height: 29.7969px;"><td style="height: 29.7969px;">ctrl + r</td><td style="height: 29.7969px;">Redo</td></tr></tbody></table>