This is a simple Vim Tutorial from vim built-in documents, you can get the whole vimtutor by typing vimtutor in shell or vimtutor -g for GUI version. It is intended to give a brief overview of the Vim editor, just enough to allow you to use the editor fairly easily.
Lesson 1: Text Editing Commands
1
2
3
4
5
6
7
8
9
10
1. The cursoris moved using either the arrow keysor the hjkl keys:
h (left) j (down) k (up) l (right)
2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
3. To exit Vim type: <ESC> :q! <ENTER>to trash allchanges.
OR type: <ESC> :wq<ENTER>to save the changes.
OR type: <ESC> shift + zz to save the changes
4. To delete the character at the cursortype: x
5. To insertorappend text type:
i type inserted text <ESC>insert before the cursor
A type appended text <ESC>append after the line
Lesson 2: Deletion Commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1. To deletefrom the cursor up to the next word type: dw
2.Todeletefrom the cursorto the endof a line type: d$
3.Todelete a whole line type: dd
4.Torepeat a motion prepend it with a number: 2w
5. The formatfor a change command is: d2w / 4dd
operator [number] motion
where:
operator - is what todo, such as d fordelete
[number] - is an optional counttorepeat the motion
motion - moves over the textto operate on, such as w, e, $, etc.
For exmaple: d2w: delete2 words
d4d: delete4lines
6.Tomoveto the startof the line use a zero: 0
7.Toundo previous actions, type: u (lowercase u)
8.Toundo all the changes on a line, type: U (capital U)
9.Toundo the undo's, type: CTRL-R
Lesson 3: Replace and Change Commands
1
2
3
4
5
6
7
8
9
1. To put back text that has just been deleted, type p .
This puts the deleted text AFTER the cursor (ifaline was deleted it will go onthelinebelowthecursor).
2. To replacethecharacter under the cursor, type r andthenthenewcharacter. eg:
Type 3rx toreplacethe3charactersby'xxx'
3. The change operator allows you to change fromthe cursor tothe motion, eg:
Type ce to change fromthe cursor totheendoftheword,
c$ to change totheendofaline.
4. The formatfor change is:
c [number] motion
Lesson 4: Jump, Search, Substitute Commands
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1. CTRL-G displays your location inthefileandthefile status
G moves totheendofthefile.
number G moves to that linenumber.
gg moves tothefirstline.
2. Typing / followed bya phrase searches FORWARD forthe phrase.
Typing ? followed bya phrase searches BACKWARD forthe phrase.
After a search type n to find the next occurrence inthe same direction
or N to search inthe opposite direction.
CTRL-O takes you back to older positions, CTRL-I to newer positions.
3. Typing % whilethe cursor is ona (,),[,],{, or } goestoitsmatch.
4. To substitute newforthefirst old inaline type :s/old/new
To substitute newfor all 'old's onalinetype :s/old/new/g
To substitute phrases between twoline#'s type :#,#s/old/new/g
To substitute all occurrences inthefile type :%s/old/new/g
To ask for confirmation eachtimeadd'c' :%s/old/new/gc
Lesson 5: Execute External Commands
1
2
3
4
5
6
7
1. :! commandexecutesanexternalcommand.
:!ls - shows adirectory listing.
:!rm FILENAME - removes file FILENAME.
2. :w fname writes the current Vim fileto disk with name FILENAME.
3. v motion :w FILENAME saves the Visually selected linesinfile FILENAME.
4. :r fname retrieves disk file FILENAME and puts it below cursor position.
5. :r !ls reads the output of ls commandandputsitbelowcursorposition.
Lesson 6: Open Append Set Commands
1
2
3
4
5
6
7
8
9
10
11
12
1. Type o to open a line BELOW the cursor and startInsert mode.
Type O toopen a line ABOVE the cursor.
2.Type a toinserttextAFTER the cursor.
Type A toinserttextafter the endof the line.
3. The e command moves to the endof a word.
4. The y operator yanks (copies) text, p puts (pastes) it.
5. Typing a capital R enters Replacemodeuntil <ESC> is pressed.
6. Typing ":set xxx"sets the option"xxx". Some options are: