Name

vim — stdin  stdout  - file  -- opt  --help  --version

Synopsis

vim [options] [files]

vim is an enhanced version of the old standard Unix editor vi. To invoke the editor in a Terminal window, run:

vim

To take the vim tutorial, run:

vimtutor

vim is a mode-based editor. It operates in two modes, insert and normal. Insert mode is for entering text in the usual manner, while normal mode is for running commands like “delete a line” or copy/paste. For basic keystrokes in normal mode, see Table 2-1.

Table 2-1. Basic keystrokes in Emacs and vim

Task

Emacs

vim

Type some text

Just type

Type i, then any text, and finally Esc

Save and quit

^x^s then ^x^c

:wq

Quit without saving

^x^c

Respond “no” when asked to save buffers

:q!

Save

^x^s

:w

Save As

^x^w

:w filename

Undo

^/ or ^x u

u

Suspend editor (not in X)

^z

^z

Switch to edit mode

(N/A)

Esc

Switch to command mode

M-x

:

Abort command in progress

^g

Esc

Move forward

^f or right arrow

l or right arrow

Move backward

^b or left arrow

h or left arrow

Move up

^p or up arrow

k or up arrow

Move down

^n or down arrow

j or down arrow

Move to next word

M-f

w

Move to previous word

M-b

b

Move to beginning of line

^a

0

Move to end of line

^e

$

Move down one screen

^v

^f

Move up one screen

M-v

^b

Move to beginning of buffer

M-<

gg

Move to end of buffer

M->

G

Delete next character

^d

x

Delete previous character

Backspace

X

Delete next word

M-d

de

Delete previous word

M-Backspace

db

Delete current line

^a^k

dd

Delete to end of line

^k

d$

Define region (type this keystroke to mark the beginning of the region, then move the cursor to the end ...

Get Macintosh Terminal Pocket Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.