Emergency vim

By Xah Lee. Date: . Last updated: .

Vim Basics, Open File, Save, Quit

vi is one of unix's fuckup. Sometimes in a emergency situation you are forced to deal with vi, and fucking unix admins refuse to install emacs. Here's your help.

To insert text, move cursor to the right place, then press i, then type your text. After you are done, type Escape to exit the insertion mode.

To delete text, move cursor to the right place and press x. (if x is inserted, that means you forgot to exit the insert mode. Type Escape to exit insertion mode. Type u to undo.)

When something doesn't work, or if you accidentally typed something and have no idea what is going on, try press Escape, then type u for undo. If a cat jumped onto your keyboard and you cannot exit vi, type the shell suspend command Ctrl+z, which should get you back on the unix command prompt, then you can kill. (by first find out the pid by ps auwwx | grep vi, then kill -9 pid).

Congratulation! You've learned emergency vi.

It may be confusing, but with the above you can edit any text files with vi.

Installing vim

What is the difference between vi and vim?

“vi” was the original editor from 1976. “vim” is “Vi IMproved”, a enhanced version started in 1991.

Basic vi Commands

Remember, in vi, it has modes. At any one time, you are either in command mode or text insertion mode. To go to the command mode, just press Escape. To go into editing mode, press i.

Switch to Command Mode

Switch to Insertion Mode

Undo, Redo

Cursor Movement

Deleting Text

Note that when you delete a word or many words, the word is automatically put into the clipboard.

Copy Text



Find Replace

Comment/Uncomment Text

Press Ctrl+v (called “visual block”), move cursor to select, then press I # Escape to insert # to all lines in the block.

To uncomment a block, do the same except just press 【x】 to kill a char.

Syntax Coloring

Line Numbers

Opening File

How to refresh buffer?

Type 【:e】

Vim Init Files

default vim init file path: ~/.vimrc

How to Remap the Escape Key?

Vim: How to Remap the Escape Key?

Ctrl+s Freezes vi

Linux: Ctrl+s Freezes vi and Terminal Key History ⌨

Microsoft Clippy in Vim