Vim Tutor: Lessons Overview
Vim Tutor: Lessons Overview
= W e l c o m e t o t h e V I M T u t o r - Version 1.7 =
===============================================================================
Vim is a very powerful editor that has many commands, too many to
explain in a tutor such as this. This tutor is designed to describe
enough of the commands that you will be able to easily use Vim as
an all-purpose editor.
ATTENTION:
The commands in the lessons will modify the text. Make a copy of this
file to practise on (if you started "vimtutor" this is already a copy).
Now, make sure that your Shift-Lock key is NOT depressed and press
the j key enough times to move the cursor so that Lesson 1.1
completely fills the screen.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.1: MOVING THE CURSOR
NOTE: If you are ever unsure about something you typed, press <ESC> to place
you in Normal mode. Then retype the command you wanted.
NOTE: The cursor keys should also work. But using hjkl you will be able to
move around much faster, once you get used to it. Really!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.2: EXITING VIM
!! NOTE: Before executing any of the steps below, read this entire lesson!!
1. Press the <ESC> key (to make sure you are in Normal mode).
3. When you see the shell prompt, type the command that got you into this
tutor. That would be: vimtutor <ENTER>
4. If you have these steps memorized and are confident, execute steps
1 through 3 to exit and re-enter the editor.
NOTE: :q! <ENTER> discards any changes you made. In a few lessons you
will learn how to save the changes to a file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.3: TEXT EDITING - DELETION
NOTE: As you go through this tutor, do not try to memorize, learn by usage.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.4: TEXT EDITING - INSERTION
2. To make the first line the same as the second, move the cursor on top
of the first character AFTER where the text is to be inserted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.5: TEXT EDITING - APPENDING
** Press A to append text. **
3. As the text has been appended press <ESC> to return to Normal mode.
4. Move the cursor to the second line marked ---> and repeat
steps 2 and 3 to correct this sentence.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1.6: EDITING A FILE
!! NOTE: Before executing any of the steps below, read this entire lesson!!
4. Save the file with changes and exit Vim with: :wq <ENTER>
5. If you have quit vimtutor in step 1 restart the vimtutor and move down to
the following summary.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 1 SUMMARY
1. The cursor is moved using either the arrow keys or the hjkl keys.
h (left) j (down) k (up) l (right)
2. To start Vim from the shell prompt type: vim FILENAME <ENTER>
NOTE: Pressing <ESC> will place you in Normal mode or will cancel
an unwanted and partially completed command.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.1: DELETION COMMANDS
NOTE: The letter d will appear on the last line of the screen as you type
it. Vim is waiting for you to type w . If you see another character
than d you typed something wrong; press <ESC> and start over.
---> There are some words that don't belong in this sentence.
5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.2: MORE DELETION COMMANDS
3. Move the cursor to the end of the correct line (AFTER the first . ).
--->
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.3: ON OPERATORS AND MOTIONS
Many commands that change text are made from an operator and a motion.
The format for a c the d delete operator is as follows:
d motion
Where:
d - is the delete operator.
motion - is what the operator will operate on (listed below).
Thus typing de will delete from the cursor to the end of the word.
NOTE: Pressing just the motion while in Normal mode without an operator will
move the cursor as specified.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.4: USING A COUNT FOR A MOTION
1. Move the cursor to the start of the line marked ---> below.
3. Type 3e to move the cursor to the end of the third word forward.
---> This is just a line with words you can move around in.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.5: USING A COUNT TO DELETE MORE
In the combination of the delete operator and a motion mentioned above you
insert a count before the motion to delete more:
d number motion
1. Move the cursor to the first UPPER CASE word in the line marked --->.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2.7: THE UNDO COMMAND
1. Move the cursor to the line below marked ---> and place it on the
first error.
2. Type x to delete the first unwanted character.
3. Now type u to undo the last command executed.
4. This time fix all the errors on the line using the x command.
5. Now type a capital U to return the line to its original state.
6. Now type u a few times to undo the U and preceding commands.
7. Now type CTRL-R (keeping CTRL key pressed while hitting R) a few times
to redo the commands (undo the undo's).
---> Fiix the errors oon thhis line and reeplace them witth undo.
8. These are very useful commands. Now move on to the Lesson 2 Summary.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 2 SUMMARY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.1: THE PUT COMMAND
3. Move the cursor to the c) line, ABOVE where the deleted line should go.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.2: THE REPLACE COMMAND
4. Repeat steps 2 and 3 until the first line is equal to the second one.
---> When this line was typed in, someone pressed some wrong keys!
---> When this line was typed in, someone pressed some wrong keys!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.3: THE CHANGE OPERATOR
** To change until the end of a word, type ce . **
3. Type ce and the correct word (in this case, type ine ).
4. Press <ESC> and move to the next character that needs to be changed.
5. Repeat steps 3 and 4 until the first sentence is the same as the second.
---> This line has a few words that need changing using the change operator.
---> This line has a few words that need changing using the change operator.
Notice that ce deletes the word and places you in Insert mode.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3.4: MORE CHANGES USING c
1. The change operator works in the same way as delete. The format is:
c [number] motion
2. The motions are the same, such as w (word) and $ (end of line).
5. Type c$ and type the rest of the line like the second and press <ESC>.
---> The end of this line needs to be corrected using the c$ command.
---> The end of this line needs to be corrected using the c$ command.
NOTE: You can use the Backspace key to correct mistakes while typing.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 3 SUMMARY
1. To put back text that has just been deleted, type p . This puts the
deleted text AFTER the cursor (if a line was deleted it will go on the
line below the cursor).
2. To replace the character under the cursor, type r and then the
character you want to have there.
3. The change operator allows you to change from the cursor to where the
motion takes you. eg. Type ce to change from the cursor to the end of
the word, c$ to change to the end of a line.
4. The format for change is:
c [number] motion
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.1: CURSOR LOCATION AND FILE STATUS
** Type CTRL-G to show your location in the file and the file status.
Type G to move to a line in the file. **
NOTE: Read this entire lesson before executing any of the steps!!
1. Hold down the Ctrl key and press g . We call this CTRL-G.
A message will appear at the bottom of the page with the filename and the
position in the file. Remember the line number for Step 3.
NOTE: You may see the cursor position in the lower right corner of the screen
This happens when the 'ruler' option is set (see :help 'ruler' )
3. Type the number of the line you were on and then G . This will
return you to the line you were on when you first pressed CTRL-G.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.2: THE SEARCH COMMAND
1. In Normal mode type the / character. Notice that it and the cursor
appear at the bottom of the screen as with the : command.
2. Now type 'errroor' <ENTER>. This is the word you want to search for.
5. To go back to where you came from press CTRL-O (Keep Ctrl down while
pressing the letter o). Repeat to go back further. CTRL-I goes forward.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.3: MATCHING PARENTHESES SEARCH
---> This ( is a test line with ('s, ['s ] and {'s } in it. ))
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4.4: THE SUBSTITUTE COMMAND
2. Type :s/thee/the <ENTER> . Note that this command only changes the
first occurrence of "thee" in the line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 4 SUMMARY
1. CTRL-G displays your location in the file and the file status.
G moves to the end of the file.
number G moves to that line number.
gg moves to the first line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
1. Type the familiar command : to set the cursor at the bottom of the
screen. This allows you to enter a command-line command.
NOTE: It is possible to execute any external command this way, also with
arguments.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.2: MORE ON WRITING FILES
4. This saves the whole file (the Vim Tutor) under the name TEST.
To verify this, type :!dir or :!ls again to see your directory.
NOTE: If you were to exit Vim and start it again with vim TEST , the file
would be an exact copy of the tutor when you saved it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.3: SELECTING TEXT TO WRITE
3. Press the : character. At the bottom of the screen :'<,'> will appear.
4. Type w TEST , where TEST is a filename that does not exist yet. Verify
that you see :'<,'>w TEST before you press <ENTER>.
5. Vim will write the selected lines to the file TEST. Use :!dir or :!ls
to see it. Do not remove it yet! We will use it in the next lesson.
NOTE: Pressing v starts Visual selection. You can move the cursor around
to make the selection bigger or smaller. Then you can use an operator
to do something with the text. For example, d deletes the text.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5.4: RETRIEVING AND MERGING FILES
2. Press v and move the cursor to the fifth item below. Notice that the
text is highlighted.
3. Press the : character. At the bottom of the screen :'<,'> will appear.
4. Type w TEST , where TEST is a filename that does not exist yet. Verify
that you see :'<,'>w TEST before you press <ENTER>.
5. Vim will write the selected lines to the file TEST. Use :!dir or :!ls
to see it. Do not remove it yet! We will use it in the next lesson.
NOTE: Pressing v starts Visual selection. You can move the cursor around
to make the selection bigger or smaller. Then you can use an operator
to do something with the text. For example, d deletes the text.
NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move
DOWN to see this lesson again.
2. Now retrieve your TEST file using the command :r TEST where TEST is
the name of the file you used.
The file you retrieve is placed below the cursor line.
3. To verify that a file was retrieved, cursor back and notice that there
are now two copies of Lesson 5.3, the original and the file version.
NOTE: You can also read the output of an external command. For example,
:r !ls reads the output of the ls command and puts it below the
cursor.
TEST
tutor
[Link]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 5 SUMMARY
2. :w FILENAME writes the current Vim file to disk with name FILENAME.
5. :r !dir reads the output of the dir command and puts it below the
cursor position.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.1: THE OPEN COMMAND
** Type o to open a line below the cursor and place you in Insert mode. **
2. Type the lowercase letter o to open up a line BELOW the cursor and place
you in Insert mode.
3. Now type some text and press <ESC> to exit Insert mode.
---> After typing o the cursor is placed on the open line in Insert mode.
fjdaiajsfa
sdsdsd
---> Open up a line above this by typing O while the cursor is on this line.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.2: THE APPEND COMMAND
1. Move the cursor to the start of the line below marked --->.
5. Use e to move to the next incomplete word and repeat steps 3 and 4.
---> This line will allow you to practice appending text to a line.
---> This line will allow you to practice appending text to a line.
NOTE: a, i and A all go to the same Insert mode, the only difference is where
the characters are inserted.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.3: ANOTHER WAY TO REPLACE
1. Move the cursor to the first line below marked --->. Move the cursor to
the beginning of the first xxx .
2. Now press R and type the number below it in the second line, so that it
replaces the xxx .
3. Press <ESC> to leave Replace mode. Notice that the rest of the line
remains unmodified.
NOTE: Replace mode is like Insert mode, but every typed character deletes an
existing character.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 6.4: COPY AND PASTE TEXT
1. Go to the line marked with ---> below and place the cursor after "a)".
2. Start Visual mode with v and move the cursor to just before "first".
6. Use Visual mode to select " item.", yank it with y , move to the end of
the next line with j$ and put the text there with p .
5. Now type the search command again and see what happens: /ignore <ENTER>
1. Type o to open a line BELOW the cursor and start Insert mode.
Type O to open a line ABOVE the cursor.
6. Typing ":set xxx" sets the option "xxx". Some options are:
'ic' 'ignorecase' ignore upper/lower case when searching
'is' 'incsearch' show partial matches for a search phrase
'hls' 'hlsearch' highlight all matching phrases
You can either use the long or the short option name.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.1: GETTING HELP
Vim has a comprehensive on-line help system. To get started, try one of
these three:
- press the <HELP> key (if you have one)
- press the <F1> key (if you have one)
- type :help <ENTER>
Read the text in the help window to find out how the help works.
Type CTRL-W CTRL-W to jump from one window to another.
Type :q <ENTER> to close the help window.
You can find help on just about any subject, by giving an argument to the
":help" command. Try these (don't forget pressing <ENTER>):
:help w
:help c_CTRL-D
:help insert-index
:help user-manual
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.2: CREATE A STARTUP SCRIPT
Vim has many more features than Vi, but most of them are disabled by
default. To start using more features you have to create a "vimrc" file.
The next time you start Vim it will use syntax highlighting.
You can add all your preferred settings to this "vimrc" file.
For more information type :help vimrc-intro
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7.3: COMPLETION
4. Press CTRL-D and Vim will show a list of commands that start with "e".
5. Press <TAB> and Vim will complete the command name to ":edit".
6. Now add a space and the start of an existing file name: :edit FIL
NOTE: Completion works for many commands. Just try pressing CTRL-D and
<TAB>. It is especially useful for :help .
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 7 SUMMARY
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes the Vim Tutor. It was intended to give a brief overview of
the Vim editor, just enough to allow you to use the editor fairly easily.
It is far from complete as Vim has many many more commands. Read the user
manual next: ":help user-manual".
This book is older and more about Vi than Vim, but also recommended:
Learning the Vi Editor - by Linda Lamb
Publisher: O'Reilly & Associates Inc.
It is a good book to get to know almost anything you want to do with Vi.
The sixth edition also includes information on Vim.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~