Vim modes
When you launch the Vim editor, you’re in normal mode.
To type a text, you need to enter the insert mode by pressing the i
key. This mode allows you to insert and delete characters in the same way you do in a regular text editor.
To go back to the normal mode from any other mode, just press the Esc
key.
Opens a file in Vim / Vi
1 |
|
Saves the file without exiting Vim / Vi
- Press
Esc
- Type
:w
- Press
Enter
To save the file under a different name, type :w new_filename
and hit Enter
.
Saves a file and quits Vim / Vi
:wq
Quits Vim / Vi without saving the file
:q!
Navigating
Moves the cursor within the whole file
Places the cursor at the start of the file
gg
Places the cursor at the end of the file
G
Moves one page forward
Ctrl
+ f
Moves one page backward
Ctrl
+ b
Place the cursor at the line 14 (go to line 14)
:14
Moves the cursor within one line
Places the cursor at the beginning of a line
0
Places the cursor at the end of a line
$
Moves the cursor forward to the beginning of a word
w
Move forward three words
3w
Move forward a WORD (any non-whitespace characters)
W
Move backward to the beginning of a word
b
Move backward three words
3b
Move backward a WORD (any non-whitespace characters)
B
Jump to the 42nd column of the current line
42|
Moves the cursor within the screen
Places the cursor at the top of the screen
H
Places the cursor at the middle of the screen
M
Places the cursor at the bottom of the screen
L
Searches for text in the document
Searches for text in the document where keyword is whatever keyword, phrase or string of characters you’re looking for.
/[keyword]
Searches the text again in whatever direction the last search was.
n
Searches your text again in the opposite direction.
N
To turn off highlighting (of text search) until the next search.
:noh
Makes the vi/vim text editor show or hide line numbers
:set number
:set nonumber
Clear all the document (select all and then delete)
ggdG