Kennisbank › Editors Terminal › Vim: the modal editor that lives in your terminal
editors terminal starter 31 August 2026

Vim: the modal editor that lives in your terminal

Vim: the modal editor that lives in your terminal Vim is a text editor built for the terminal, a direct descendant of the original Unix `vi`, and it ships by

If you have ever typed `vim /etc/hosts`, seen the cursor sit there refusing to respond to your keystrokes, and reached for `Ctrl+C`, you are the target audience. The editor is not broken. You are in the wrong mode.

Requirements

You need a Linux, macOS, or BSD system with a terminal. Vim 9.x is the current stable line; Vim 8.2 is still widely deployed on older distributions and works fine for everything below. On Debian and Ubuntu, install `vim` rather than `vim-tiny`, because the minimal package lacks syntax highlighting, multi-level undo, and the `+clipboard` feature.

```bash sudo apt update sudo apt install vim ```

On RHEL, Rocky, AlmaLinux, or Fedora:

```bash sudo dnf install vim-enhanced ```

On Arch:

```bash sudo pacman -S vim ```

You should have write access to your home directory, because Vim stores its configuration in `~/.vimrc` and its plugins under `~/.vim/`. No root access is needed for anything in this article after the install step.

Step 1 — Confirm which Vim you actually have

There are several binaries named `vim`, and they are not the same program. On minimal systems, `vim` is often a symlink to `vim.tiny`, which silently drops features you will later assume are present.

```bash vim --version | head -n 5 ```

The output lists the version number and a long line of `+` and `-` flags. The flags matter more than the number. Check for `+syntax`, `+undo`, `+clipboard`, and `+python3`. A minus sign means the feature was compiled out, and no amount of `.vimrc` editing will bring it back.

If you see `vim.tiny` in the first line, install the full package as shown above.

Step 2 — Learn the modes before you learn the commands

Vim is modal. Every keystroke means something different depending on which mode you are in, and this is the single design decision that makes or breaks the editor for new users.

Normal mode is where you land when Vim opens. Keys are commands: `h`, `j`, `k`, `l` move the cursor left, down, up, and right. `dd` deletes a line. `yy` copies one. Nothing you type appears in the file.

Insert mode is where text goes in. You reach it with `i` (insert before cursor), `a` (append after cursor), or `o` (open a new line below). You leave it with `Esc`.

Visual mode selects text. Press `v` for character selection, `V` for line selection, `Ctrl+v` for block selection.

Command-line mode runs ex commands. Type `:` from normal mode and you get a prompt at the bottom for things like `:w` (write), `:q` (quit), and `:wq` (both).

The reason for this split is efficiency. In a non-modal editor, every command needs a modifier key, which is why you end up with `Ctrl+Shift+Alt+P`. Vim spends one keystroke to switch modes and then gives every letter back to you as a command. The cost is a learning curve measured in days, not minutes.

Step 3 — Edit a file without panicking

Open a scratch file and run through the minimum viable workflow.

```bash vim /tmp/practice.txt ```

Press `i`, type a few lines, then press `Esc`. Type `:w` and hit Enter to save. Type `:q` to quit. If you made changes you did not save, `:q` refuses; use `:q!` to discard them.

That is the whole editor in four commands. Everything else is refinement.

Step 4 — Write a `.vimrc` that does something

Vim's defaults are conservative because they date back to terminals that could not do more. A `.vimrc` is where you turn on the features you expect from a modern editor.

```bash cat > ~/.vimrc <<'EOF' " Vim 9.x configuration set nocompatible " disable vi compatibility mode set number " show line numbers set relativenumber " show relative line numbers set tabstop=4 " tab width set shiftwidth=4 " indent width set expandtab " tabs become spaces set smartindent " auto-indent new lines set ignorecase " case-insensitive search set smartcase " ...unless the pattern has capitals set incsearch " search as you type set hlsearch " highlight matches set undofile " persistent undo across sessions set undodir=~/.vim/undo " where undo files live set clipboard=unnamedplus " use the system clipboard set mouse=a " mouse support in terminals that allow it syntax on " syntax highlighting filetype plugin indent on " language-aware indentation EOF ```

Two lines need explanation. `set nocompatible` disables the vi compatibility mode that Vim falls back to when it finds no `.vimrc`; without it, several of the settings below behave differently or not at all. `set undofile` writes undo history to disk, so you can close a file on Friday and undo Thursday's mistake on Monday. That requires the `~/.vim/undo` directory to exist.

```bash mkdir -p ~/.vim/undo ```

The `clipboard=unnamedplus` setting makes yanks and pastes go through the system clipboard. It only works if your Vim was compiled with `+clipboard`. On a headless server without X11, it will silently do nothing, which is fine — you did not have a clipboard to share anyway.

Step 5 — Install a plugin manager

Vim's built-in package system works, but it has no update mechanism. For anything beyond a handful of plugins, use `vim-plug`. It is a single file, it is fast, and it does not require Node.js or Python at runtime.

```bash curl -fLo ~/.vim/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim ```

Then add a plugin block to your `.vimrc`:

```bash cat >> ~/.vimrc <<'EOF'

call plug#begin('~/.vim/plugged') Plug 'tpope/vim-fugitive' " Git integration Plug 'preservim/nerdtree' " file tree Plug 'airblade/vim-gitgutter' " diff markers in the gutter call plug#end() EOF ```

Open Vim and run `:PlugInstall`. Each plugin is fetched from GitHub into `~/.vim/plugged/`. To update later, run `:PlugUpdate`. To remove a plugin, delete its `Plug` line and run `:PlugClean`.

The cost of this approach: your editor now depends on GitHub being reachable, and plugin updates are manual. If you want automatic updates and a Lua-based configuration, Neovim with `lazy.nvim` is the modern alternative, and it is genuinely better at both. Vim remains the safer choice on servers where you cannot install a newer runtime.

Step 6 — Search and replace across a project

Vim's `:grep` and `:vimgrep` search from inside the editor. `:vimgrep` uses Vim's own regex engine and works everywhere; `:grep` shells out to an external tool.

```vim :vimgrep /TODO/g **/*.py :copen ```

The first command searches every `.py` file under the current directory for `TODO` and loads the matches into the quickfix list. The second opens that list in a split window. Press Enter on a match to jump to it, `:cnext` and `:cprev` to move through the rest.

For large codebases, install `ripgrep` and point Vim at it:

```bash sudo apt install ripgrep ```

```vim set grepprg=rg\ --vimgrep\ --smart-case set grepformat=%f:%l:%c:%m ```

Now `:grep pattern` is fast enough that you will stop leaving the editor to search.

Step 7 — Use Vim over SSH without surprises

The reason Vim matters on servers is that it is already installed on almost every Unix system you will ever log into. You do not need to install anything on the remote host to edit a config file.

```bash ssh user@server sudo vim /etc/nginx/nginx.conf ```

Two things to know in this context. First, if your terminal is not reporting its type correctly, arrow keys may insert `A`, `B`, `C`, `D` instead of moving the cursor. Fix it by setting `TERM` on the remote side:

```bash export TERM=xterm-256color ```

Second, `sudo vim` uses root's `.vimrc`, not yours. If you want your settings when editing system files, use `sudo -e`, which copies the file to a temporary location, opens it with your own Vim configuration, and writes it back on save.

```bash sudo -e /etc/nginx/nginx.conf ```

That is the difference between editing a file and editing a file with an editor you know how to use.

Verification

Check that your configuration loaded and the features you care about are active:

```bash vim --version | grep -E '\+syntax|\+undo|\+clipboard' ```

All three should show a `+`. Then open Vim and run these two commands from normal mode:

```vim :echo has('syntax') :echo has('persistent_undo') ```

Both should print `1`. If `persistent_undo` returns `0`, your `undodir` directory does not exist or is not writable.

Finally, confirm your `.vimrc` is being read:

```vim :echo $MYVIMRC ```

The output should be `/home/youruser/.vimrc`. If it is empty, Vim did not find the file, and none of your settings are active.

Common problems

Arrow keys print letters instead of moving the cursor. Your terminal type is wrong or Vim is running in vi-compatibility mode. Set `export TERM=xterm-256color` and make sure `set nocompatible` is the first line of your `.vimrc`.

`:w` fails with `E212: Can't open file for writing`. You opened a root-owned file without `sudo`. Save with `:w !sudo tee %` from inside Vim, or quit and reopen with `sudo -e`.

Plugins do not load after `:PlugInstall`. The `call plug#end()` line is missing, or it appears before the last `Plug` line. Everything between `plug#begin()` and `plug#end()` is the plugin block; nothing outside it is read.

Vim will still be on the server you SSH into five years from now, in the same place, with the same keybindings. That is either the most reassuring thing about it or the most annoying, depending on how much of your `.vimrc` you have memorized.

← Terug naar kennisbank
← Terug naar kennisbank