A quick start guide for beginners to the Vim text editor
- By Christopher Kielty, last updated May 15, 2018
- Getting Started
- Command Mode for moving around and editing, Insert Mode for entering text
- Vim starts in command mode
- I puts you into insert mode
- esc gets you back into command mode
- Modes are awesome but take time to get used to
- Basic Usage
- Start Vim:
- Insert mode: I
- Command mode: esc
- Quit without saving:
- Save and quit:
- Delete one word: D - W(D then W)
- Delete one line: D - D
- (Visual Mode) highlight text: V
- (Visual Mode) yank highlighted text: Y
- (Visual Mode) delete highlighted text: D
- Paste below or after cursor: P
- Paste above or before cursor: shift + P
- Undo: U
- Redo: control + R
- (that's control while holding down on R)
- Moving Around
- Left: Hdown: Jup: Kright: L
- Skip ahead one word: W
- Skip back one word: B
- Move to beginning of line: 0
- Move to end of line: $
- Move forward one sentence: )
- Move backward one sentence: (
- Move to top of document: G - G
- Move to bottom of document: shift + G
- Move to last edited text: ` - .
- Center screen: Z - Z
Start vim with the name of the file you want to edit:
If the file exists, Vim opens it. If the file doesn’t exist, Vim creates it in the current directory and opens it.
Vim has multiple modes. Vim starts in command mode, which is good for moving around and editing text.
Switch to insert mode to enter text by hitting I. Think I for insert.
Get back to command mode with esc
1,44 at the bottom right of the screen.
1 indicates the line number while
44 indicates the character number on that line.
See also: An attempt to list all Linux text editors.
To exit Vim, first make sure you're in command mode (esc).
Quit without saving:
Save and exit:
Editing with command and visual mode
- delete word:
- delete line:
In Vim, when you delete something, you’re actually cutting it. To paste, use either lower or upper case P.
If you wanna select some text, then copy/cut/delete it, use visual mode.
- enter visual mode:
- copy (yank) selected text:
- delete/cut selected text:
- undo changes:
Moving around with command mode
Arrow keys work just fine in command/visual mode and in insert mode. However, if you want to move around a Vim document with a little less effort, here are some of the keys to do that.
- move forward one word:
- move backward one word:
- move to the beginning of the current line:
- move to the end of the current line:
- move forward one sentence:
- move back one sentence:
- move to the top of the document:
- move to the bottom of the document:
- move to the last thing that was edited in the document:
- center the screen on cursor: