- Lesson 1.1- Moving the cursor
- Lesson 1.2 - INPUT AND OUTPUT VIM
- Lesson 1.3 - TEXT EDITING – DELETION
- Lesson 1.4: TEXT EDITING – INSERTION
- Lesson 2.1- Clear
- Lesson 2.2 - MORE CLEAR
- Lesson 2.3- COMMANDS AND OBJECTS
- Lesson 2.4 - AN EXCEPTION TO 'COMMAND-OBJECT'
- Lesson 2.5 – CANCELLATION
- Lesson 3.1- THE BONDING
- Lesson 3.2 - THE REPLACEMENT
- Lesson 3.3 - THE CHANGING
- Lesson 3.4 - MORE CHANGES WITH c
- Lesson 4.1- POSITION AND STATUS FILE
- Lesson 4.2 - THE SEARCH
- Lesson 4.3 - SEARCH parenthesis
- Lesson 4.4 - HOW TO CORRECT AN ERROR
- Lesson 5.1 - How to execute an external command
- Lesson 5.2 - MORE DETAILS ON THE RECORDING FILES
- Lesson 5.3 - A SELECTIVE RECORDING
- Lesson 5.4 - FUSION AND RECOVERY OF FILES
- Lesson 6.1 - THE OPENING
- Lesson 6.2 – ADDING
- Lesson 6.3 - ANOTHER VERSION OF REPLACEMENT
- Lesson 6.4 - Setting the options
- Lesson 7 - ACCESS TO ONLINE HELP
- Lesson 8 - CREATING A SCRIPT START
Vim is a very powerful editor who has too many commands to all explained in a course like this, which is designed to describe sufficiently so you can just use Vim. The time required for this course is about 25 to 30 minutes, depending the time you spend experimenting. The commands used in lessons change the text. Make a copy of this file to above yourself (if you started "vimtutor" this is already a copy). It is important to keep in mind that this course is designed to teach through practice. This means that you must run the commands to learn properly. If you only read the text, you forget the commands! Now, make sure your keyboard is not locked on uppercase.
Lesson 1.1- Moving the cursor
To move the cursor, press the keys h, j, k, l as indicated:
Tip: The PM is on the left and moves left.
The key is the right and moves right.
J key looks like a down arrow.
Note: If you are unsure of what you just typed, press <Esc>
to return to normal mode. Then retype the command you want.
Note: The arrow keys should also work. But using
hjkl you can move much faster, once
you get used.
Lesson 1.2 - INPUT AND OUTPUT VIM
1. Press and hold <Esc> (to be sure you are in Normal mode).
2. Type: q! <enter>
---> This will leave the editor without saving the changes you have made.
If you want to save changes and exit, type:
: Wq <Enter>
3. When the prompt 'shell' will be presented, type the command
brought you in this tutorial. This could be: vimtutor <Enter>
Normally you would use: vim tutor <Enter>
---> 'Vim' starts the editor, 'tutor' is the file you want to edit.
Lesson 1.3 - TEXT EDITING – DELETION
In Normal mode, press x to delete the character under the cursor.
Lesson 1.4: TEXT EDITING – INSERTION
In Normal mode, press i to insert text.
SUMMARY OF LESSON 1
1. The cursor moves with the arrow keys or the keys hjkl.
h (left) j (down) k (top) l (right)
2. To enter Vim (with the% prompt) type: vim <Enter> FILE
3. To exit Vim type: <Esc>: q! <Enter> To lose all
OR type: <Esc>: wq to save the <Enter>
4. To delete a character under the cursor in Normal mode type: x
5. To insert text at the cursor in Normal mode type:
I type the text <Esc>
NOTE: Pressing <Esc> puts you in Normal mode or cancels an order
partially typed that you do want more.
Lesson 2.1- Clear
Type dw to delete to the end of a word.
NOTE: The letters dw will appear as the last line of the screen when
you type. If you have typed something wrong, press <Esc> and
Lesson 2.2 - MORE CLEAR
Type d $ to delete to the end of the line.
Lesson 2.3- COMMANDS AND OBJECTS
The format of the erase command d is as follows:
[Number] d object OR d [number] object
number - is how often execute the order (optional, default: 1).
d - is the erase command.
object - is what the command will operate (see list below).
A short list of items:
w - the cursor to the end of the word, including the following.
e - the cursor to the end of the word without the space below.
$ - Cursor to the end of the line.
NOTE: For the adventurous, the only support of object in Normal mode, without
command, move the cursor as shown in the list of objects.
Lesson 2.4 - AN EXCEPTION TO 'COMMAND-OBJECT'
Type dd to delete a line.
Given the number of times we unregister full lines, designers
Vi decided it would be easier to just type two of the
continued to clear a line.
Lesson 2.5 – CANCELLATION
Type u to undo the last commands.
Type U to retrieve a line.
Typing Ctrl + R to cancel cancellations
SUMMARY OF LESSON 2
1. To clear the cursor to the end of a word type: dw
2. To clear the cursor to the end of a line type: d $
3. To delete a line type: dd
4. The format of a Normal mode command is:
[number] command object OR command [number] object
number - is how often to repeat the command
command - is what to do, such as d for delete
object - is what the command should act, for example w (word)
$ (Until the end of the line), etc..
5. To undo previous actions, type: u (u lowercase)
To undo all changes on a line type: U (capital U)
To cancel the cancellation type: Ctrl-R
Lesson 3.1- THE BONDING
Type p to put the cursor after what has been erased.
1. Place the cursor on the first line of the poem below.
2. Type dd to delete the line and place it in the Vim buffer.
3. Move the cursor to the previous line where you want
put the line cleared.
4. In Normal mode, type p to get the line.
Lesson 3.2 - THE REPLACEMENT
Type r and a character to replace the character under the cursor.
Lesson 3.3 - THE CHANGING
To change all or part of a word, type cw
Note that cw deletes the word and then puts you into insert mode.
Lesson 3.4 - MORE CHANGES WITH c
The change works with the same objects as delete.
1. The change works the same way as the deletion.
The format is:
[Number] c object OR c [number] object
2. The objects are also the same: w (word), $ (end of line) etc..
SUMMARY OF THE LESSON 3
1. To replace text that has been deleted, type p. This places the
deleted text AFTER the cursor (if a line has been erased, it
will be under the cursor).
2. To replace the character under the cursor, type r followed by the character
which will replace the original.
3. The change allows you to change the specified object, the cursor to
the end of the object. For example, type cw to change the cursor
until the end of the word, c $ to change until the end of a line.
4. The format for the change is:
[Number] c object OR c [number] object
Lesson 4.1- POSITION AND STATUS FILE
Type Ctrl-G to display your position in the file and its status.
Use Shift-G to go to a given line in the file.
Note: Read this entire lesson before making any step!
1. Hold down the Ctrl key and press G. A status line
will appear at the bottom of the screen with the file name and number of the
where you are. Note this number, it will be used in step 3.
2. Type capital G (Shift-G) to get to the end of the file.
3. Enter the line number where you were followed by Shift-G. This will
back to the line where you were initially.
(When you type the numbers, they do not appear on the screen).
Lesson 4.2 - THE SEARCH
Type /followed by a text to search for that text.
1. Type the character /Normal mode. Note that it and the cursor
appear at the bottom of the screen, like when we used:.
2. Then type 'errrooorrr' <Enter>. This is the word you want to search.
3. To find again the same text, simply type n.
To find the same text in the opposite direction, type Shift-N.
4. If you want to search for a text to the top of the file, use?
in place of /.
Note: When the search reaches the end of the file, it returns to the beginning.
Lesson 4.3 - SEARCH parenthesis
Type% to find),] or) correspondents.
Note: This feature is very useful when debugging a program that
contains unbalanced parentheses!
Lesson 4.4 - HOW TO CORRECT AN ERROR
Type: s/old/new/g to replace 'old' with 'new'.
: s/lee/the <Enter>.
Note that this command changes only the first occurrence on
: s/lee/the/g, ordered to make a global substitution
on the line. This changes all occurrences on the line
To change all occurrences of a text between two lines,
type: #, # s/old/new/g where #, # are the numbers of the two lines.
Type:% s/old/new/g to change every occurrence in any
SUMMARY OF THE LESSON 4
1. Ctrl-G displays your position in the file and the status thereof.
Shift-G puts you at the end of the file. A line number followed by Shift-G
you up to this line.
2. Type / followed by a text search the text forward.
Type? followed by a text search the text backwards.
After a search type n to find the next occurrence in the
same direction or Shift-N to search in the opposite direction.
3. Typing% while the cursor is on (,) [,], () or moves
it on the character.
4. To replace the first by aa bb on one line type: s/aa/bb
To replace all by aa bb on one line type: s/aa/bb/g
To replace text between two numbers line type: #, # s/aa/bb/g
To replace all occurrences in file type:% s /aa/bb/g
To request a confirmation each time add 'c':% s/aa/bb/gc
Lesson 5.1 - How to execute an external command
Type:! followed by an external command to execute this command.
1. Type the: familiar to the slider at the bottom of the screen. This will
can enter a command.
2. Then type a! (exclamation point). This allows you to perform
any valid command for your interpreter (shell).
3. For example, type ls after! and press <Enter>. This brings up
the list of files in the current folder, as if you had typed the
command at the shell prompt. Use:! Dir if! Ls does not.
Note: It is possible to execute any command of this external
Note: All commands must end with mint <Enter>.
Lesson 5.2 - MORE DETAILS ON THE RECORDING FILES
To save the changes made to the file, type: w file.
1. Type:! Or dir:! Ls for a list of files in the folder
common. You already know that we must support <Enter> after that.
2. Choose a file name that does not yet exist, for example TEST.
3. Then type: w TEST (where TEST is the name you choose).
4. This backup file (Tutorial Vim) under the name TEST.
To check, type:! Re visualize dir for the folder contents.
Note that if you quit Vim and return with the test file, it
will be an exact copy of the course when you've saved.
5. Now delete the file by typing (MS-DOS)::! Del TEST
Or (Unix)::! Rm TEST
Lesson 5.3 - A SELECTIVE RECORDING
To save a portion of a file, type: #, # w FILE
To save only a portion of a file, type: #, # w TEST
where #, # are the two numbers you have noted (top, bottom) and TEST is
the file name.
Lesson 5.4 - FUSION AND RECOVERY OF FILES
To insert the contents of a file, type: r file
The file you retrieve is placed where the cursor is located.
SUMMARY OF THE LESSON 5
1. :! command executes an external command.
:! dir:! ls displays the contents of the folder.
:! Del FILE:! Rm deleted files FILE.
2. : w file saves the current Vim file on the disk with
3. : #, # w file records with the lines # # in the file FILE.
4. r ROSTER FILE retrieves the file and inserts it into the file
Current from the cursor position.
Lesson 6.1 - THE OPENING
Type o to open a line under the cursor and go to Insert.
Open a line above by typing Shift-O while the cursor is here.
Lesson 6.2 – ADDING
Type a to insert text AFTER the cursor.
Type an a (lowercase) to add text after the character
under the cursor. (A capital adds text to the end of the line).
Lesson 6.3 - ANOTHER VERSION OF REPLACEMENT
Type a capital R to replace more than one character.
Lesson 6.4 - Setting the options
An option to solve the research and ignores the alternative
1. Search for 'unknown' by typing / ignore.
Repeat this several times using the n.
2. Enable 'ic' (Ignore case) by typing: set ic.
3. Then continue your search by using n.
Repeat this search several times with the n key.
4. Enable the 'hlsearch' and 'incsearch' with: set hls is.
5. Then try a search, and take care that what is
Product: / ignore.
6. To stop the highlight of the results, type:
SUMMARY OF THE LESSON 6
1. Type o opens a line under the cursor and place it in fashion
Insertion. Type a capital O opens a line above the line
where the cursor is located.
2. Enter one has to insert text AFTER the character where the
cursor. Type a capital letter A adds text to the end
of the line.
3. Type a capital R Replacing active mode until the
key <Esc> to be backed out.
4. Type: set xxx activates the option 'xxx'.
Lesson 7 - ACCESS TO ONLINE HELP
Using the online help system.
Vim has a comprehensive system of online help. To get there, try one of
these three methods:
- Press the button <Help> (if you have one)
- Press the button <F1> (if you have one)
- Type: help <Enter>
Type: q <Enter> to close the Help window.
You can get help on almost any subject by giving
arguments to the command: help. Try for example (do not forget
: Help w
: Help c_ <T
: Help insert-index
: Help user-manual
Lesson 8 - CREATING A SCRIPT START
Enable Vim features.
Vim has many more features than Vi, but most of them
are disabled by default. To start using them, you must
create a file "vimrc".
1. Start editing the file "vimrc". This depends on your system:
: Edit ~ /. Vimrc for Unix
: Edit $ VIM / _vimrc for MS-Windows
2. Integrate now the text of the file "vimrc" for example:
: $ VIMRUNTIME read/vimrc_example.vim
3. Save the file with:
The next time you start Vim, the highlighting will be syntactic
activated. You can add all your favorite settings in this file.