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
| Flag | Meaning |
|---|---|
| :wq | Write the file and quit; :x does the same |
| :q! | Quit and throw every change away |
| i | Enter insert mode; Esc goes back to normal mode |
| dd | Delete the current line; u undoes the last change |
| /word | Search forward; n jumps to the next hit |
| :%s/old/new/g | Replace throughout the file |
| -R | Open read-only so you cannot save by accident |
Examples
vim +100 config.ymlOpens at line 100.
vim -d a.txt b.txtOpens the two files side by side as a diff.
vim -R big.logReads 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