Why I use vim

I think there are a lot of people like me who, even having GNOME Text Editor or some KDE equivalent available, still use vim as their primary text editor.

I have been using vim since my first days with Linux back in 1997. At the time it was perhaps the only option — or one of very few. It was not easy, but coming from WordStar and WordPerfect, it did not look as intimidating as it might to someone picking it up today. Those editors also had modes and keyboard-driven workflows, so the mental model was not entirely foreign.

I write this as a personal reference for the commands I use most and keep forgetting, since I do not use all of them every day. I update it over time.

What is vim

vim (Vi IMproved) is a text editor created in 1991 by Bram Moolenaar, based on the original vi written by Bill Joy in 1976 for Unix systems. It is available on virtually every Linux, BSD, and macOS system, which makes knowing it worthwhile — when you connect to a server with nothing installed, vim (or vi) is almost certainly there.

The most important concept: modes

Vim has modes. This is what confuses new users most. There is no single state where typing inserts text and keyboard shortcuts work simultaneously — they are separate modes.

Mode How to enter What it does
Normal Esc (from any mode) Navigate, delete, copy, paste, run commands
Insert i, a, o Type text
Visual v, V, Ctrl+v Select text
Command : (from Normal) Save, quit, search/replace, settings

When you open vim you are in Normal mode. Press i to start typing. Press Esc to go back to Normal.

Opening files

vim filename.txt
vim /etc/nginx/nginx.conf

Open a file from inside vim (Normal mode):

:e filename.txt

Navigation (Normal mode)

Basic movement:

Key Action
h Left
j Down
k Up
l Right
w Next word
b Previous word
0 Start of line
$ End of line
gg First line of file
G Last line of file
:n Go to line n (e.g. :42)
Ctrl+f Page down
Ctrl+b Page up

Entering Insert mode

Key Where it inserts
i Before cursor
a After cursor
I Start of line
A End of line
o New line below
O New line above

Deleting text (Normal mode)

Key What it deletes
x Character under cursor
dw Word from cursor
dd Entire line
d$ From cursor to end of line
dgg From cursor to first line
dG From cursor to last line

Numbers multiply any command: 5dd deletes 5 lines, 3dw deletes 3 words.

Copy and paste (Normal mode)

y is "yank" (copy), p is paste.

Key Action
yy Copy current line
yw Copy word
y$ Copy to end of line
p Paste after cursor
P Paste before cursor

Visual mode — select text

Press v to enter Visual mode, then move the cursor to select. Once selected:

Key Action
y Copy selection
d Delete selection
> Indent selection
< Unindent selection

V selects whole lines. Ctrl+v selects a rectangular block.

Undo and redo

Key Action
u Undo
Ctrl+r Redo

Search

From Normal mode:

/pattern        search forward
?pattern        search backward
n               next match
N               previous match

Search and replace

:%s/old/new/g           replace all in file
:%s/old/new/gc          replace all, confirm each
:10,20s/old/new/g       replace in lines 10 to 20

Flags: g = all occurrences per line, c = confirm, i = case insensitive, I = case sensitive.

Saving and quitting

Command Action
:w Save
:w filename Save as
:q Quit (fails if unsaved changes)
:q! Quit discarding changes
:wq Save and quit
ZZ Save and quit (Normal mode shortcut)
ZQ Quit without saving (Normal mode shortcut)

Useful .vimrc settings

~/.vimrc is vim's config file. A minimal setup:

syntax on           " syntax highlighting
set number          " show line numbers
set tabstop=4       " tab = 4 spaces
set expandtab       " use spaces instead of tabs
set hlsearch        " highlight search matches
set incsearch       " search as you type
set ignorecase      " case insensitive search...
set smartcase       " ...unless pattern has uppercase

Learn interactively

vim ships with a built-in tutorial. Run it from the terminal:

vimtutor

It takes about 30 minutes and covers everything in this guide hands-on.

See also

man vim, :help inside vim (extensive built-in documentation).

  • Created: November 20, 2007
  • Last edited: July 7, 2026