~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~ W e l c o m e t o V I M T u t o r - V e r s i o n 1 . 5 ~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 1.0 * ************** 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 so that you will be able to easily use Vim as an all-purpose editor. The approximate time required to complete the tutor is 30 minutes, depending upon how much time is spent with experimentation. It is important to remember that this tutor is set up for "learning by doing". That means that the student needs to execute the commands to learn them properly. ATTENTION: Since you will be modifying this file, make sure it is a copy of the original one! Now, scoll down with the cursor keys (or the page-down key) so that Lesson 1.1 completely fills the screen. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 1.1 * ************** =====>>>>> MOVING THE CURSOR <<<<<===== ** To move the curor, press the cursor keys as usual. Also, try the keys space, return, and backspace. On some terminals, the keyboard might not have cursor keys (in particular, on ancient hardware :), or the cursor keys might not work because you logged on via a weird setup. In that cases, it is helpful to know that you can move the cursor without cursor keys: ** To move the cursor, press the h,j,k,l keys as indicated. ** ^ k Hint: The h key is at the left and moves left. < h l > The l key is at the right and moves right. j The j key looks like a down arrow v 1. Move the cursor around the screen until you are comfortable. 2. Hold down the down key (j) until it repeats. ---> Now you know how to move to the next lesson. 3. Using the down key, move to Lesson 1.2. Note: If you are ever unsure about something you typed, press to place you in Command Mode. Then retype the command you wanted. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 1.2 * ************** =====>>>>> ENTERING AND EXITING VIM <<<<<===== !! NOTE: Before executing any of the steps below, read this entire lesson!! 1. Press the key (to make sure you are in Command Mode). 2. Type :q! . ---> This exits the editor WITHOUT saving any changes you have made. If you want to save the changes and exit type ZZ (Some people type :wq, but ZZ is safer in case the disk is full.) 3. When you see the shell prompt (%) type: vim -g tutor.txt . (You can omit the option -g; then, vim does not open its own window.) ---> 'vim' means enter the vim editor, 'tutor' is the file you wish to edit. 4. If you have these steps memorized and are confident, execute steps 1 through 3 to exit and re-enter the editor. Then cursor down to Lesson 1.3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 1.3 * ************** =====>>>>> TEXT EDITING - DELETION <<<<<===== ** While in Command Mode press x to delete the character under the cursor. ** ---> You can tell that you are NOT in command mode when on the bottom line at the left side you see something like "-- INSERT --", "-- REPLACE --", or "-- VISUAL --". If so, press to go back to command mode (the "-- ... --" will disappear). 1. Move the cursor to the line below marked --->. 2. To fix the errors, move the cursor until it is on top of the character to be deleted. 3. Press the x key to delete the unwanted character. 4. Sometimes, it can be convenient to remove the character to the *left* of the cursor. Press the X key to do that. 5. Repeat steps 2 through 4 until the sentence is correct. ---> The ccow jumpedd ovverr thhe mooon. 5. Now that the line is correct, go on to Lesson 1.4. NOTE: As you go through this tutor, do not try to memorize, learn by doing! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 1.4 * ************** =====>>>>> TEXT EDITING - INSERTION <<<<<===== ** While in Command Mode press i to insert text. ** 1. Move the cursor to the first line below marked --->. 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. 3. Press i and type in the necessary additions. When you have finished an insertion, press to return to Command Mode. 4. Sometimes, it can be more convenient to insert the new text *after* the current cursor position (hence "add"). Try that too by pressing a and then typing the insertion. 5. Repeat steps 2 through 4 to correct the sentence. ---> There is text misng this . ---> There is some text missing from this line. 5. When you are comfortable inserting text move to the summary below. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ******************** * LESSON 1 SUMMARY * ******************** 1. The cursor is moved using either the arrow keys or the h,j,k,l keys. h (left) j (down) k (up) l (right) 2. To enter Vim (from the % prompt) type: % vim FILENAME 3. To exit Vim type: :q! (exits without saving and without prompting) OR type: ZZ to save the changes. 4. To delete a character under the cursor type: x (in command mode) 5. To insert text at the cursor while in Command Mode type: i type in text a type in text to add text after cursor position. NOTE: Pressing will place you in Command Mode or will cancel any partially completed command. (Command Mode is sort of vim's "home state".) Now continue with Lesson 2. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************* * INTERPLAY * ************* =====>>>>> ABOUT MODES <<<<<===== At a few points in the previous (first) lesson, you were asked to go to "command mode" or to make sure that you are in "command mode". It is about time to tell you a little bit more about that. Vim has several modes. In the last line of the window at the left, the mode which vim is in is (usually) displayed by "-- MODE --". Therefore, the last line is called the "status line". The command mode is not displayed; if nothing is displayed, then you are in command mode. Command mode is sort of vim's home state (traditionally). Of course, you could change that so that insert mode, say, is the default mode. However, I suggest to stick with command mode - you will see that it does make sense. In order to get back to command mode you press . This works always and everywhere, no matter what you have typed, and no matter which mode you are in right now. What are modes for? Command mode is where you give commands to vim, such as "delete", "editor another file", or "search and replace", and so on. From command mode, you can enter other modes. In the other modes you can do other things (such as typing text), but you can not give real commands to the editor. When in any of the other modes, you can get back to command mode by typing the key. The other modes are (sorted approximately by frequency): o Insert mode: in this mode you write (or overwrite) new text. It is entered by a "insert" command, or a "change", "append", etc. o Replace mode: in this mode you replace old text by new text. It is almost the same as insert mode. o Visual mode: this mode is for highlighting text. You enter this mode by starting to highlight text. After you highlighted it, you can do something with it, for instance, change it, delete it, make a copy of it, etc. Doing so will also exit visual mode and go back to command mode. o There are one (or two?) other modes, which are, IMHO, less important, so I will not confuse you here :) And since vim is being developed actively, more modes might be invented :) If the mode is not displayed (for instance, if "-- INSERT --" is not displayed although you typed i ), then you can do either of the following: 1) Get my (GZ's) "vimrc" files from http://www.igd.fhg.de/~zach/vim. Put those files in your home (Unix) as ~/.vimrc, etc. Then exit vim and start it again. or 2) Put the following line in your ~/.vimrc: :set showmode (If there is no such file yet, create one.) Then exit vim and start it again. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 2.1 * ************** =====>>>>> DELETION COMMANDS <<<<<===== ** Type dw to delete to the end of a word. ** 1. Press to make sure you are in Command Mode. 2. Move the cursor to the line below marked --->. 3. Move the cursor to the beginning of a word that needs to be deleted. 4. Type dw to make the word disappear. NOTE: The letters dw will appear on the last line of the screen as you type them. If you typed something wrong, press and start over. As soon as vim has recognized them to be a command, it will execute it and the characters on the last line will disappear. ---> There are a some words fun that don't belong paper 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 <<<<<===== ** Type d$ to delete to the end of the line. ** 1. Press to make sure you are in Command Mode. 2. Move the cursor to the line below marked --->. 3. Move the cursor to the end of the correct line (AFTER the first . ). 4. Type d$ to delete to the end of the line. ---> Somebody typed the end of this line twice. end of this line twice. 5. Move on to Lesson 2.3 to understand what is happening. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 2.3 * ************** =====>>>>> ON COMMANDS AND MOTIONS <<<<<===== The format for the d delete command is as follows: [number] d motion OR d [number] motion Where: number - is how many times to execute the command (optional, default=1). d - is the command to delete. motion - is what the command will operate on (listed below). A short list of motions: w - from the cursor to the end of the word, including the space. e - from the cursor to the end of the word, NOT including the space. $ - from the cursor to the end of the line. Actually, these are commands to move the cursor. You can press just the "motion" while in command mode. For instance, place the cursor anywhere in the following line and type w a few times. You already know a few other motion commands, which you can try out after the 'd' command. --> The quick cursor jumps from word to word when you press w ... The logic behind this is: You type a text operation command (a single letter) and then a cursor motion command (another letter). This makes the text operation command operate on the whole text range from where the cursor was to where the cursor would have been moved by the motion command. Remember: You can save a whole lot of typing or fiddling with the mouse if you know vim's motion commands by heart (or rather, spinal :) ! Note: Historically, the "motions" have been called text "objects" in vi. However, I feel that "motion" is more appropriate, especially since vim has other "commands" which match the notion of text objects much more precisely. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 2.4 * ************** =====>>>>> AN EXCEPTION TO 'COMMAND-MOTION' <<<<<===== ** Type dd to delete a whole line. ** Due to the frequency of whole line deletion, the designers of Vim decided it would be easier to simply type two d's in a row to delete a line. (And 'd' is not a motion or text object, so there is no ambiguity.) 1. Move the cursor to the second line in the phrase below. 2. Type dd to delete the line. 3. Now move to the fourth line. 4. Type 2dd (remember number-command-object) to delete the two lines. --> 1) Roses are red, 2) Mud is fun, 3) Violets are blue, 4) I have a car, 5) Clocks tell time, 6) Sugar is sweet 7) And so are you. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 2.5 * ************** =====>>>>> THE UNDO COMMAND <<<<<===== ** Press u to undo the last commands, U to fix a whole line. ** 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 * ******************** 1. To delete from the cursor to the end of a word type: dw 2. To delete from the cursor to the end of a line type: d$ 3. To delete a whole line type: dd 4. The format for a command in command mode is: [number] command motion OR command [number] motion where: number - is how many times to repeat the command command - is what to do, such as d for delete motion - is what the command should act upon, such as w (till end ofword), $ (to the end of line), etc. 5. To undo previous actions, type: u (lowercase u) To undo all the changes on a line type: U (capital U) To redo the undo's type: CTRL-R ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 3.1 * ************** =====>>>>> THE PUT COMMAND <<<<<===== ** Type p to put the last deletion after the cursor. ** (0. If you're not in command mode, type now.) 1. Move the cursor to the first line in the set below. 2. Type dd to delete the line and store it in Vim's buffer. 3. Move the cursor to line (c). 4. While in command mode, type p to replace the line. 5. Repeat steps 2 through 4 to put all the lines in correct order. d) Can you learn too? b) Violets are blue, c) Intelligence is learned, a) Roses are red, ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 3.2 * ************** =====>>>>> THE REPLACE COMMAND <<<<<===== ** Type r and a character to replace the character under the cursor. ** 1. Move the cursor to the first line below marked --->. 2. Move the cursor so that it is on top of the first error. 3. Type r and then the character which should replace the error. You'll notice that you don't have to type to get out of this kind of replacement mode. 4. Repeat steps 2 and 3 until the first line is correct. ---> Whan this lime was tuoed in, someone presswd some wrojg keys! ---> When this line was typed in, someone pressed some wrong keys! NOTE: Remember that you should be learning by doing, not memorization. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 3.3 * ************** =====>>>>> ANOTHER VERSION OF REPLACE <<<<<===== ** Type a capital R to replace more than one character. ** 1. Move the cursor to the first line below marked --->. 2. Place the cursor at the beginning of the first word that is different from the second line marked ---> (the word 'last'). 3. Now type R and replace the remainder of the text on the first line by typing over the old text to make the first line the same as the second. When you're done, press ---> To make the first line the same as the last on this page use the keys. ---> To make the first line the same as the second, type R and the new text. 4. Note that when you press to exit, any unaltered text remains. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 3.4 * ************** =====>>>>> THE CHANGE COMMAND <<<<<===== ** To change part or all of a word, type cw . ** 1. Move the cursor to the first line below marked --->. 2. Place the cursor on the u in lubw. 3. Type cw and the correct word (in this case, type 'ine'.) Typing cw will place you in insert mode until you press . 4. Press and move to the next error (the first character to be changed). 5. Repeat steps 3 and 4 until the first sentence is the same as the second. ---> This lubw has a few wptfd that mrrf changing usf the change command. ---> This line has a few words that need changing using the change command. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 3.5 * ************** =====>>>>> MORE CHANGES USING c <<<<<===== ** The change command is used with the same motions as delete. ** 1. The change command works in the same way as delete. The format is: [number] c motions OR c [number] motions So, pretty often you will type c2w or cc. 2. The motions are also the same, such as w (word), $ (end of line), etc. 3. Move to the first line below marked --->. 4. Move the cursor to the first error. 5. Type c$ to make the rest of the line like the second and press . ---> The end of this line needs some help to make it like the second. ---> The end of this line needs to be corrected using the c$ command. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ******************** * LESSON 3 SUMMARY * ******************** 1. To replace text that has already 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 which will replace the original. 3. Typing a capital R enters replace mode until is pressed to exit. 4. The change command allows you to change the specified object from the cursor to the end of the object. eg. Type cw to change from the cursor to the end of the word, c$ to change to the end of a line. 5. The format for change is: [number] c motion OR c [number] motion Now go on to the next lesson. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************* * INTERPLAY * ************* =====>>>>> ABOUT LOWERCASE AND UPPERCASE COMMANDS <<<<<===== You already know the 'r' and the 'R' commands which both replace something, although they behave slightly differently. And you know the 'u' and the 'U' commands which both undo, although they behave slightly differently. Notice something? There is a scheme behind this! In general, all frequent commands come in a lowercase and an uppercase variant. They both have the same meaning, but they behave slightly differently. Usually, the uppercase variant Here is a table comparing the lower- and uppercase variants of the more frequent commands: command detailed lower upper detailed insert insert at current i I insert at beginning of cursor position current line delete delete until cursor motion !!!! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 4.1 * ************** =====>>>>> LOCATION AND FILE STATUS <<<<<===== ** Type CTRL-g to show your location in the file and the file status. Type SHIFT-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 . A status line will appear at the bottom of the page with the filename and the line you are on. Remember the line number for Step 3. 2. Press shift-G to move you to the bottom of the file. 3. Type in the number of the line you were on and then shift-G. This will return you to the line you were on when you first pressed Ctrl-g. (When you type in the numbers, they will NOT be displayed on the screen.) 4. If you feel confident to do this, execute steps 1 through 3. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 4.2 * ************** =====>>>>> THE SEARCH COMMAND <<<<<===== ** Type / followed by a phrase to search for the phrase. ** 1. In command 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' . This is the word you want to search for. 3. To search for the same phrase again, simply type n . To search for the same phrase in the opposite direction, type Shift-N . 4. If you want to search for a phrase in the backwards direction, use the command ? instead of /. ---> When the search reaches the end of the file it will continue at the start. "errroor" is not the way to spell error; errroor is an error. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 4.3 * ************** =====>>>>> THE SUBSTITUTE COMMAND <<<<<===== ** Type :s/old/new/g to substitute 'new' for 'old'. ** 1. Move the cursor to the line below marked --->. 2. Type :s/thee/the . Note that this command only changes the first occurrence on the line. 3. Now type :s/thee/the/g meaning substitute globally on the line. This changes all occurrences on the line. ---> thee best time to see thee flowers is in thee spring. 4. To change every occurrence of a character string 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 the whole file. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 4.4 * ************** =====>>>>> MATCHING PARENTHESES SEARCH <<<<<===== ** Type % to find a matching ),], or } . ** 1. Place the cursor on any (, [, or { in the line below marked --->. 2. Now type the % character. 3. The cursor should be on the matching parenthesis or bracket. 4. Type % to move the cursor back to the first bracket (by matching). ---> This ( is a test line with ('s, ['s ] and {'s } in it. )) Note: This is very useful in debugging a program with unmatched parentheses! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ******************** * LESSON 4 SUMMARY * ******************** 1. Ctrl-g displays your location in the file and the file status. Shift-G moves to the end of the file. A line number followed by Shift-G moves to that line number. 2. Typing / followed by a phrase searches FORWARD for the phrase. Typing ? followed by a phrase searches BACKWARD for the phrase. 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 a (,),[,],{, or } locates its matching pair. 4. To substitute new for the first old on a line type :s/old/new To substitute new for all 'old's on a line type :s/old/new/g To substitute phrases between two line #'s type :#,#s/old/new/g To substitute all occurrences in the file type :%s/old/new/g To ask for confirmation each time add 'c' :%s/old/new/gc ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 5.1 * ************** =====>>>>> MORE ON WRITING FILES <<<<<===== ** To save the changes made to the file, type :w FILENAME. ** 1. Choose a filename that is not already in your current directory, such as TEST. 2. Now type: :w TEST (where TEST is the filename you chose.) 3. This saves the whole file (Vim Tutor) under the name TEST. ---> Note that if you were to exit Vim and enter again with the filename TEST, the file would be an exact copy of the tutor when you saved it. (4. Don't forget to remove the file :) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 5.2 * ************** =====>>>>> A SELECTIVE WRITE COMMAND <<<<<===== ** To save part of the file, type :#,# w FILENAME ** 1. Choose a temporary filename such as TEST. 2. Move the cursor to the top of this page and type Ctrl-g to find the number of that line. Remember this number! 3. Now move to the bottom of the page and type Ctrl-g again. Remember this line number also! 4. To save ONLY a section to a file, type :#,#w TEST where #,# are the two numbers you remembered (top,bottom) and TEST is your filename. 5. Again, see that the file is there but do not remove it. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 5.3 * ************** =====>>>>> RETRIEVING AND MERGING FILES <<<<<===== ** To insert the contents of a file, type :r FILENAME ** 1. Place the cursor at the top of this page. NOTE: After executing Step 3 you will see Lesson 5.2. Then move DOWN to this lesson again. 3. Now retrieve your TEST file using the command :r TEST where TEST is the name of the file. NOTE: The file you retrieve is placed starting where the cursor is located. 4. 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. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ******************** * LESSON 5 SUMMARY * ******************** 1. :w FILENAME writes the current Vim file to disk with name FILENAME. 2. :#,#w FILENAME saves the lines # through # in file FILENAME. 3. :r FILENAME retrieves file FILENAME and inserts it into the current file following the cursor position. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 6.1 * ************** =====>>>>> THE OPEN COMMAND <<<<<===== ** Type o to open a line below the cursor and place you in insert mode. ** 1. Move the cursor to the line below marked --->. 2. Type o (lowercase) to open up a line BELOW the cursor and place you in insert mode. 3. Now copy the line marked ---> and press to exit insert mode. ---> After typing o the cursor is placed on the open line in insert mode. 4. To open up a line ABOVE the cursor, simply type a capital O , rather than a lowercase o. Try this on the line below. Open up a line above this by typing Shift-O while the cursor is on this line. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 6.2 * ************** =====>>>>> THE APPEND COMMAND <<<<<===== ** Type A to insert text at the END of a line. ** 1. Move the cursor to the first line below marked ---> 2. Type an A (shift-a) to append text to the end of the line. 3. Now complete the first line. Note also that append is exactly the same as insert mode, except for the location where text is inserted. ---> This line will allow you to practice ---> This line will allow you to practice appending text to the end of a line. NOTE: you should already know how to add text after the current cursor position! If not, go back to the lesson on inserting text. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************** * Lesson 6.3 * ************** =====>>>>> SET VIM OPTION <<<<<===== ** Change vim's environment so a search or substitute ignores case ** 1. Search for 'ignore' by entering: /ignore Repeat several times by hitting the n key 2. Set the 'ic' (Ignore case) variable by typing: :set ignorecase 3. Now search for 'IGNORE' again by entering: n Repeat search several more times by hitting the n key 4. Go back to case-sensitive searching by switching the option off by typing :set noignorecase NOTE: For help on a certain vim variable type :help 'ignorecase' for instance. For a list of all variables (called "options" in vim parlance) type :help options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ******************** * LESSON 6 SUMMARY * ******************** 1. Typing o opens a line BELOW the cursor and places the cursor on the open line in insert mode. Typing a capital O opens the line ABOVE the line the cursor is on. 2. Type an a to insert text AFTER the character the cursor is on. Typing a capital A automatically appends text to the end of the line. 3. Typing ":set xxx" sets the vim option "xxx" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ************* * LESSON 7 * ************* =====>>>>> ON-LINE HELP COMMANDS <<<<<===== 1. Vim has a comprehensive on-line help system. To get started, type :help The window should be split now and the cursor should be in the help window. 2. Type Now the cursor should be in this window again at its former position. Type again. 3. Now move the cursor down a few pages to the line which says |X_ma| motion: Marks |X_et| External commands Move the cursor to anywhere on the string |X_ma| and type Ctrl-] . This will jump to help related to the associated topic. (If ti doesn't, see step 5.) 4. Go back by typing Ctrl-o . 5. Hold the Control-key and click with the left mouse button on |X_ma|. This has the same effect as step 3. Under Windows with a German keyboard, step 3 might not work at all, so this might be the only way to get there comfortably. 6. Type :q to close the help window. NOTES: You can find help on just about any subject, by giving an argument to the ":help" command. Try these: Type :help w Type :h c_ Type :help insert-index ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Macros, abbreviations, the shift-logic (o/O, a/A, r/R, ...) visual mode vimrc files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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. For further reading and studying, it is a good idea to browse through some of the help using the commands in Lesson 7. You will not be able to memorize all the commands at once, but if you try to remember what capabilities vim has, and occassionally review some of the online documentation you will become a power user of vim. This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado School of Mines using ideas supplied by Charles Smith, Colorado State University. E-mail: bware@mines.colorado.edu. Modified for Vim by Bram Moolenaar. Modified by Gabriel Zachmann (GZ) (zach@igd.fhg.de); geared towards the frequently used features when programming with vim. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ vim:set tabstop=8 shiftwidth=8: