Home·Terminal commands

vim

Text processing

Usage

vim [file]

A modal editor: typing does nothing until you press i, and you leave with Esc then :wq to save or :q! to discard.

Common flags

FlagMeaning
:wqWrite the file and quit; :x does the same
:q!Quit and throw every change away
iEnter insert mode; Esc goes back to normal mode
ddDelete the current line; u undoes the last change
/wordSearch forward; n jumps to the next hit
:%s/old/new/gReplace throughout the file
-ROpen read-only so you cannot save by accident

Examples

vim +100 config.yml

Opens at line 100.

vim -d a.txt b.txt

Opens the two files side by side as a diff.

vim -R big.log

Reads a log without any risk of writing to it.

These were built to be piped together. Three joined commands are usually shorter than one that does everything.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does vim do?

A modal editor: typing does nothing until you press i, and you leave with Esc then :wq to save or :q! to discard.

Q. How do I type it?

vim [file] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

7 are listed here; the full set is in man vim. This command sits under Text processing.

Related commands

man page: man vim