1# Welcome to the VIM Tutor 2 3Vim is a very powerful editor that has many commands, too many to explain in 4a tutor such as this. This tutor is designed to describe enough of the 5commands that you will be able to easily use Vim as an all-purpose editor. 6It is IMPORTANT to remember that this tutor is set up to teach by use. That 7means that you need to do the exercises to learn them properly. If you only 8read the text, you will soon forget what is most important! 9 10For now, make sure that your Shift-Lock key is NOT depressed and press the 11`j`{normal} key enough times to move the cursor so that Lesson 0 completely 12fills the screen. 13 14# Lesson 0 15 16NOTE: The commands in the lessons will modify the text, but those changes 17won't be saved. Don't worry about messing things up; just remember that 18pressing [<Esc>](<Esc>) and then [u](u) will undo the latest change. 19 20This tutorial is interactive, and there are a few things you should know. 21- Type [<Enter>](<Enter>) on links [like this](holy-grail ) to open the linked help section. 22- Or simply type [K](K) on any word to find its documentation! 23- Sometimes you will be required to modify text like 24 25 this here 26 27Once you have done the changes correctly, the ✗ sign at the left will change 28to ✓. I imagine you can already see how neat Vim can be. ;) 29Other times, you'll be prompted to run a command (I'll explain this later): 30~~~ cmd 31 :help <Enter> 32~~~ 33or press a sequence of keys 34~~~ normal 35 <Esc>0f<Space>d3wP$P 36~~~ 37Text within <'s and >'s (like `<Enter>`{normal}) describes a key to press 38instead of text to type. 39 40Now, move to the next lesson (use the `j`{normal} key to scroll down). 41 42## Lesson 1.1: MOVING THE CURSOR 43 44** To move the cursor, press the `h`, `j`, `k`, `l` keys as indicated. ** 45 46 ↑ 47 k Hint: The `h`{normal} key is at the left and moves left. 48 ← h l → The `l`{normal} key is at the right and moves right. 49 j The `j`{normal} key looks like a down arrow. 50 ↓ 51 52 1. Move the cursor around the screen until you are comfortable. 53 54 2. Hold down the down key (`j`{normal}) until it repeats. 55 Now you know how to move to the next lesson. 56 57 3. Using the down key, move to Lesson 1.2. 58 59NOTE: If you are ever unsure about something you typed, press <Esc> to place 60 you in Normal mode. Then retype the command you wanted. 61 62NOTE: The cursor keys should also work. But using hjkl you will be able to 63 move around much faster, once you get used to it. Really! 64 65# Lesson 1.2: EXITING VIM 66 67!! NOTE: Before executing any of the steps below, read this entire lesson !! 68 69 1. Press the <Esc> key (to make sure you are in Normal mode). 70 71 2. Type: 72 73 `:q!`{vim} `<Enter>`{normal}. 74 75 This exits the editor, DISCARDING any changes you have made. 76 77 3. Open vim and get back here by executing the command that got you into 78 this tutor. That might be: 79 80 :Tutor <Enter> 81 82 4. If you have these steps memorized and are confident, execute steps 83 1 through 3 to exit and re-enter the editor. 84 85NOTE: [:q!](:q) <Enter> discards any changes you made. In a few lessons you 86 will learn how to save the changes to a file. 87 88 5. Move the cursor down to Lesson 1.3. 89 90## Lesson 1.3: TEXT EDITING - DELETION 91 92** Press `x`{normal} to delete the character under the cursor. ** 93 94 1. Move the cursor to the line below marked ✗. 95 96 2. To fix the errors, move the cursor until it is on top of the 97 character to be deleted. 98 99 3. Press [the x key](x) to delete the unwanted character. 100 101 4. Repeat steps 2 through 4 until the sentence is correct. 102 103The ccow jumpedd ovverr thhe mooon. 104 105 5. Now that the line is correct, go on to Lesson 1.4. 106 107NOTE: As you go through this tutor, do not try to memorize everything, 108 your Vim vocabulary will expand with usage. Consider returning to 109 this tutor periodically for a refresher. 110 111# Lesson 1.4: TEXT EDITING: INSERTION 112 113** Press `i`{normal} to insert text. ** 114 115 1. Move the cursor to the first line below marked ✗. 116 117 2. To make the first line the same as the second, move the cursor on top 118 of the first character AFTER where the text is to be inserted. 119 120 3. Press `i`{normal} and type in the necessary additions. 121 122 4. As each error is fixed press `<Esc>`{normal} to return to Normal mode. 123 Repeat steps 2 through 4 to correct the sentence. 124 125There is text misng this . 126There is some text missing from this line. 127 128 5. When you are comfortable inserting text move to Lesson 1.5. 129 130# Lesson 1.5: TEXT EDITING: APPENDING 131 132** Press `A`{normal} to append text. ** 133 134 1. Move the cursor to the first line below marked ✗. 135 It does not matter on what character the cursor is in that line. 136 137 2. Press [A](A) and type in the necessary additions. 138 139 3. As the text has been appended press `<Esc>`{normal} to return to Normal 140 mode. 141 142 4. Move the cursor to the second line marked ✗ and repeat 143 steps 2 and 3 to correct this sentence. 144 145There is some text missing from th 146There is some text missing from this line. 147There is also some text miss 148There is also some text missing here. 149 150 5. When you are comfortable appending text move to Lesson 1.6. 151 152# Lesson 1.6: EDITING A FILE 153 154** Use `:wq`{vim} to save a file and exit. ** 155 156!! NOTE: Before executing any of the steps below, read this entire lesson !! 157 158 1. Exit this tutor as you did in Lesson 1.2: `:q!`{vim} 159 Or, if you have access to another terminal, do the following there. 160 161 2. At the shell prompt type this command: 162~~~ sh 163 $ nvim tutor 164~~~ 165 'nvim' is the command to start the Nvim editor, 'tutor' is the name of 166 the file you wish to edit. Use a file that may be changed. 167 168 3. Insert and delete text as you learned in the previous lessons. 169 170 4. Save the file with changes and exit Vim with: 171~~~ cmd 172 :wq 173~~~ 174 Note you'll need to press `<Enter>` to execute the command. 175 176 5. If you have quit vimtutor in step 1 restart the vimtutor and move down 177 to the following summary. 178 179 6. After reading the above steps and understanding them: do it. 180 181# Lesson 1 SUMMARY 182 183 1. The cursor is moved using either the arrow keys or the hjkl keys. 184 h (left) j (down) k (up) l (right) 185 186 2. To start Vim from the shell prompt type: 187~~~ sh 188 $ nvim FILENAME 189~~~ 190 3. To exit Vim type: `<Esc>`{normal} `:q!`{vim} `<Enter>`{normal} to trash all changes. 191 OR type: `<Esc>`{normal} `:wq`{vim} `<Enter>`{normal} to save the changes. 192 193 4. To delete the character at the cursor type: `x`{normal} 194 195 5. To insert or append text type: 196 `i`{normal} insert text `<Esc>`{normal} insert before the cursor. 197 `A`{normal} append text `<Esc>`{normal} append after the line. 198 199NOTE: Pressing `<Esc>`{normal} will place you in Normal mode or will cancel 200 an unwanted and partially completed command. 201 202Now continue with Lesson 2. 203 204# Lesson 2.1: DELETION COMMANDS 205 206** Type `dw`{normal} to delete a word. ** 207 208 1. Press `<Esc>`{normal} to make sure you are in Normal mode. 209 210 2. Move the cursor to the line below marked ✗. 211 212 3. Move the cursor to the beginning of a word that needs to be deleted. 213 214 4. Type [d](d)[w](w) to make the word disappear. 215 216There are a some words fun that don't belong paper in this sentence. 217 218 5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2. 219 220# Lesson 2.2: MORE DELETION COMMANDS 221 222** Type `d$`{normal} to delete to the end of the line. ** 223 224 1. Press `<Esc>`{normal} to make sure you are in Normal mode. 225 226 2. Move the cursor to the line below marked ✗. 227 228 3. Move the cursor to the end of the correct line (AFTER the first . ). 229 230 4. Type `d$`{normal} to delete to the end of the line. 231 232Somebody typed the end of this line twice. end of this line twice. 233 234 5. Move on to Lesson 2.3 to understand what is happening. 235 236# Lesson 2.3: ON OPERATORS AND MOTIONS 237 238Many commands that change text are made from an [operator](operator) and a [motion](navigation). 239The format for a delete command with the [d](d) delete operator is as follows: 240 241 d motion 242 243 Where: 244 d - is the delete operator. 245 motion - is what the operator will operate on (listed below). 246 247 A short list of motions: 248 [w](w) - until the start of the next word, EXCLUDING its first character. 249 [e](e) - to the end of the current word, INCLUDING the last character. 250 [$]($) - to the end of the line, INCLUDING the last character. 251 252 Thus typing `de`{normal} will delete from the cursor to the end of the word. 253 254NOTE: Pressing just the motion while in Normal mode without an operator 255 will move the cursor as specified. 256 257# Lesson 2.4: USING A COUNT FOR A MOTION 258 259** Typing a number before a motion repeats it that many times. ** 260 261 1. Move the cursor to the start of the line marked ✓ below. 262 263 2. Type `2w`{normal} to move the cursor two words forward. 264 265 3. Type `3e`{normal} to move the cursor to the end of the third word forward. 266 267 4. Type `0`{normal} ([zero](0)) to move to the start of the line. 268 269 5. Repeat steps 2 and 3 with different numbers. 270 271This is just a line with words you can move around in. 272 273 6. Move on to Lesson 2.5. 274 275# Lesson 2.5: USING A COUNT TO DELETE MORE 276 277** Typing a number with an operator repeats it that many times. ** 278 279In the combination of the delete operator and a motion mentioned above you 280insert a count before the motion to delete more: 281 d number motion 282 283 1. Move the cursor to the first UPPER CASE word in the line marked ✗. 284 285 2. Type `d2w`{normal} to delete the two UPPER CASE words 286 287 3. Repeat steps 1 and 2 with a different count to delete the consecutive 288 UPPER CASE words with one command 289 290This ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up. 291 292# Lesson 2.6: OPERATING ON LINES 293 294** Type `dd`{normal} to delete a whole line. ** 295 296Due to the frequency of whole line deletion, the designers of Vi decided 297it would be easier to simply type two d's to delete a line. 298 299 1. Move the cursor to the second line in the phrase below. 300 2. Type [dd](dd) to delete the line. 301 3. Now move to the fourth line. 302 4. Type `2dd`{normal} to delete two lines. 303 3041) Roses are red, 3052) Mud is fun, 3063) Violets are blue, 3074) I have a car, 3085) Clocks tell time, 3096) Sugar is sweet 3107) And so are you. 311 312# Lesson 2.7: THE UNDO COMMAND 313 314** Press `u`{normal} to undo the last commands, `U`{normal} to fix a whole line. ** 315 316 1. Move the cursor to the line below marked ✗ and place it on the first error. 317 2. Type `x`{normal} to delete the first unwanted character. 318 3. Now type `u`{normal} to undo the last command executed. 319 4. This time fix all the errors on the line using the `x`{normal} command. 320 5. Now type a capital `U`{normal} to return the line to its original state. 321 6. Now type `u`{normal} a few times to undo the `U`{normal} and preceding commands. 322 7. Now type `<C-r>`{normal} (Control + R) a few times to redo the commands. 323 324Fiix the errors oon thhis line and reeplace them witth undo. 325 326 8. These are very useful commands. Now move on to the Lesson 2 Summary. 327 328# Lesson 2 SUMMARY 329 330 1. To delete from the cursor up to the next word type: `dw`{normal} 331 2. To delete from the cursor to the end of a line type: `d$`{normal} 332 3. To delete a whole line type: `dd`{normal} 333 4. To repeat a motion prepend it with a number: `2w`{normal} 334 335 5. The format for a change command is: 336 337 operator [number] motion 338 339 where: 340 341 operator - is what to do, such as [d](d) for delete 342 [number] - is an optional count to repeat the motion 343 motion - moves over the text to operate on, such as: 344 [w](w) (word), 345 [$]($) (to the end of line), etc. 346 347 6. To move to the start of the line use a zero: [0](0) 348 349 7. To undo previous actions, type: `u`{normal} (lowercase u) 350 To undo all the changes on a line, type: `U`{normal} (capital U) 351 To undo the undo's, type: `<C-r>`{normal} 352 353# Lesson 3.1: THE PUT COMMAND 354 355** Type `p`{normal} to put previously deleted text after the cursor. ** 356 357 1. Move the cursor to the first ✓ line below. 358 359 2. Type `dd`{normal} to delete the line and store it in a Vim register. 360 361 3. Move the cursor to the c) line, ABOVE where the deleted line should go. 362 363 4. Type `p`{normal} to put the line below the cursor. 364 365 5. Repeat steps 2 through 4 to put all the lines in correct order. 366 367d) Can you learn too? 368b) Violets are blue, 369c) Intelligence is learned, 370a) Roses are red, 371 372# Lesson 3.2: THE REPLACE COMMAND 373 374** Type `rx`{normal} to replace the character at the cursor with x. ** 375 376 1. Move the cursor to the first line below marked ✗. 377 378 2. Move the cursor so that it is on top of the first error. 379 380 3. Type `r`{normal} and then the character which should be there. 381 382 4. Repeat steps 2 and 3 until the first line is equal to the second one. 383 384Whan this lime was tuoed in, someone presswd some wrojg keys! 385When this line was typed in, someone pressed some wrong keys! 386 387 5. Now move on to Lesson 3.3. 388 389NOTE: Remember that you should be learning by doing, not memorization. 390 391# Lesson 3.3: THE CHANGE OPERATOR 392 393** To change until the end of a word, type `ce`{normal}. ** 394 395 1. Move the cursor to the first line below marked ✗. 396 397 2. Place the cursor on the "u" in "lubw". 398 399 3. Type `ce`{normal} and the correct word (in this case, type "ine" ). 400 401 4. Press `<Esc>`{normal} and move to the next character that needs to be changed. 402 403 5. Repeat steps 3 and 4 until the first sentence is the same as the second. 404 405This lubw has a few wptfd that mrrf changing usf the change operator. 406This line has a few words that need changing using the change operator. 407 408Notice that [c](c)e deletes the word and places you in Insert mode. 409 410# Lesson 3.4: MORE CHANGES USING `c`{normal} 411 412** The change operator is used with the same motions as delete. ** 413 414 1. The change operator works in the same way as delete. The format is: 415 416 c [number] motion 417 418 2. The motions are the same, such as `w`{normal} (word) and `$`{normal} (end of line). 419 420 3. Move to the first line below marked ✗. 421 422 4. Move the cursor to the first error. 423 424 5. Type `c$`{normal} and type the rest of the line like the second and press `<Esc>`{normal}. 425 426The end of this line needs some help to make it like the second. 427The end of this line needs to be corrected using the `c$`{normal} command. 428 429NOTE: You can use the Backspace key to correct mistakes while typing. 430 431# Lesson 3 SUMMARY 432 433 1. To put back text that has just been deleted, type [p](p). This puts the 434 deleted text AFTER the cursor (if a line was deleted it will go on the 435 line below the cursor). 436 437 2. To replace the character under the cursor, type [r](r) and then the 438 character you want to have there. 439 440 3. The [change operator](c) allows you to change from the cursor to where 441 the motion takes you. Type `ce`{normal} to change from the cursor to the 442 end of the word, `c$`{normal} to change to the end of a line. 443 444 4. The format for change is: 445 446 c [number] motion 447 448Now go on to the next lesson. 449 450# Lesson 4.1: CURSOR LOCATION AND FILE STATUS 451 452** Type `<C-g>`{normal} to show your location in a file and the file status. 453 Type `G`{normal} to move to a line in the file. ** 454 455NOTE: Read this entire lesson before executing any of the steps!! 456 457 1. Hold down the `<Ctrl>`{normal} key and press `g`{normal}. We call this `<C-g>`{normal}. 458 A message will appear at the bottom of the page with the filename and 459 the position in the file. Remember the line number for Step 3. 460 461NOTE: You may see the cursor position in the lower right corner of the 462 screen. This happens when the ['ruler']('ruler') option is set. 463 464 2. Press [G](G) to move you to the bottom of the file. 465 Type [gg](gg) to move you to the start of the file. 466 467 3. Type the number of the line you were on and then `G`{normal}. This will 468 return you to the line you were on when you first pressed `<C-g>`{normal}. 469 470 4. If you feel confident to do this, execute steps 1 through 3. 471 472# Lesson 4.2: THE SEARCH COMMAND 473 474** Type `/`{normal} followed by a phrase to search for the phrase. ** 475 476 1. In Normal mode type the `/`{normal} character. Notice that it and the 477 cursor appear at the bottom of the screen as with the `:`{normal} command. 478 479 2. Now type 'errroor' `<Enter>`{normal}. This is the word you want to search for. 480 481 3. To search for the same phrase again, simply type [n](n). 482 To search for the same phrase in the opposite direction, type [N](N). 483 484 4. To search for a phrase in the backward direction, use [?](?) instead of `/`{normal}. 485 486 5. To go back to where you came from press `<C-o>`{normal}. 487 (keep `<Ctrl>`{normal} pressed down while pressing the letter `o`{normal}). 488 Repeat to go back further. `<C-i>`{normal} goes forward. 489 490"errroor" is not the way to spell error; errroor is an error. 491 492NOTE: When the search reaches the end of the file it will continue at the 493 start, unless the ['wrapscan']('wrapscan') option has been reset. 494 495# Lesson 4.3: MATCHING PARENTHESES SEARCH 496 497** Type `%`{normal} to find a matching ),], or }. ** 498 499 1. Place the cursor on any (, [, or { in the line below marked ✓. 500 501 2. Now type the [%](%) character. 502 503 3. The cursor will move to the matching parenthesis or bracket. 504 505 4. Type `%`{normal} to move the cursor to the other matching bracket. 506 507 5. Move the cursor to another (,),[,],{ or } and see what `%`{normal} does. 508 509This ( is a test line with ('s, ['s ] and {'s } in it. )) 510 511NOTE: This is very useful in debugging a program with unmatched parentheses! 512 513# Lesson 4.4: THE SUBSTITUTE COMMAND 514 515** Type `:s/old/new/g` to substitute "new" for "old". ** 516 517 1. Move the cursor to the line below marked ✗. 518 519 2. Type 520~~~ cmd 521 :s/thee/the/ 522~~~ 523 NOTE: the [:s](:s) command only changed the first match of "thee" in the line. 524 525 3. Now type 526~~~ cmd 527 :s/thee/the/g 528~~~ 529 Adding the g [flag](:s_flags) means to substitute globally in the line, 530 change all occurrences of "thee" in the line. 531 532Usually thee best time to see thee flowers is in thee spring. 533 534 4. To change every occurrence of a character string between two lines, type 535~~~ cmd 536 :#,#s/old/new/g 537~~~ 538 where #,# are the line numbers of the range of lines where the 539 substitution is to be done. 540 541 Type 542~~~ cmd 543 :%s/old/new/g 544~~~ 545 to change every occurrence in the whole file. 546 547 Type 548~~~ cmd 549 :%s/old/new/gc 550~~~ 551 to find every occurrence in the whole file, with a prompt whether to 552 substitute or not. 553 554# Lesson 4 SUMMARY 555 556 1. `<C-g>`{normal} displays your location and the file status. 557 `G`{normal} moves to the end of the file. 558 number `G`{normal} moves to that line number. 559 `gg`{normal} moves to the first line. 560 561 2. Typing `/`{normal} followed by a phrase searches FORWARD for the phrase. 562 Typing `?`{normal} followed by a phrase searches BACKWARD for the phrase. 563 After a search type `n`{normal} to find the next occurrence in the same 564 direction or `N`{normal} to search in the opposite direction. 565 `<C-o>`{normal} takes you back to older positions, `<C-i>`{normal} to 566 newer positions. 567 568 3. Typing `%`{normal} while the cursor is on a (,),[,],{, or } goes to its 569 match. 570 571 4. To substitute new for the first old in a line type 572~~~ cmd 573 :s/old/new 574~~~ 575 To substitute new for all 'old's on a line type 576~~~ cmd 577 :s/old/new/g 578~~~ 579 To substitute phrases between two line #'s type 580~~~ cmd 581 :#,#s/old/new/g 582~~~ 583 To substitute all occurrences in the file type 584~~~ cmd 585 :%s/old/new/g 586~~~ 587 To ask for confirmation each time add 'c' 588~~~ cmd 589 :%s/old/new/gc 590~~~ 591 592# Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND 593 594** Type `:!`{vim} followed by an external command to execute that command. ** 595 596 1. Type the familiar command `:`{normal} to set the cursor at the bottom of 597 the screen. This allows you to enter a command-line command. 598 599 2. Now type the [!](!cmd) (exclamation point) character. This allows you to 600 execute any external shell command. 601 602 3. As an example type "ls" following the "!" and then hit `<Enter>`{normal}. 603 This will show you a listing of your directory, just as if you were 604 at the shell prompt. 605 606NOTE: It is possible to execute any external command this way, also with 607 arguments. 608 609NOTE: All `:`{vim} commands must be finished by hitting `<Enter>`{normal}. 610 From here on we will not always mention it. 611 612# Lesson 5.2: MORE ON WRITING FILES 613 614** To save the changes made to the text, type `:w`{vim} FILENAME. ** 615 616 1. Type `:!ls`{vim} to get a listing of your directory. 617 You already know you must hit `<Enter>`{normal} after this. 618 619 2. Choose a filename that does not exist yet, such as TEST. 620 621 3. Now type: 622~~~ cmd 623 :w TEST 624~~~ 625 (where TEST is the filename you chose.) 626 627 4. This saves the whole file (the Vim Tutor) under the name TEST. 628 To verify this, type `:!ls`{vim} again to see your directory. 629 630NOTE: If you were to exit Vim and start it again with `nvim TEST`, the file 631 would be an exact copy of the tutor when you saved it. 632 633 5. Now remove the file by typing: 634~~~ cmd 635 :!rm TEST 636~~~ 637# Lesson 5.3: SELECTING TEXT TO WRITE 638 639** To save part of the file, type `v`{normal} motion `:w FILENAME`{vim}. ** 640 641 1. Move the cursor to this line. 642 643 2. Press [v](v) and move the cursor to the fifth item below. Notice that the 644 text is highlighted. 645 646 3. Press the `:`{normal} character. At the bottom of the screen 647 648 `:'<,'>`{vim} 649 650 will appear. 651 652 4. Type 653 654 `:w TEST`{vim} 655 656 where TEST is a filename that does not exist yet. Verify that you see 657 658 `:'<,'>w TEST`{vim} 659 660 before you press `<Enter>`{normal}. 661 662 5. Vim will write the selected lines to the file TEST. Use `:!ls`{vim} to see it. 663 Do not remove it yet! We will use it in the next lesson. 664 665NOTE: Pressing [v](v) starts [Visual selection](visual-mode). You can move the cursor around to 666 make the selection bigger or smaller. Then you can use an operator to 667 do something with the text. For example, `d`{normal} deletes the text. 668 669# Lesson 5.4: RETRIEVING AND MERGING FILES 670 671** To insert the contents of a file, type `:r FILENAME`{vim}. ** 672 673 1. Place the cursor just above this line. 674 675NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move 676 DOWN to see this lesson again. 677 678 2. Now retrieve your TEST file using the command 679 680 `:r TEST`{vim} 681 682 where TEST is the name of the file you used. 683 The file you retrieve is placed below the cursor line. 684 685 3. To verify that a file was retrieved, cursor back and notice that there 686 are now two copies of Lesson 5.3, the original and the file version. 687 688NOTE: You can also read the output of an external command. For example, 689 690 `:r !ls`{vim} 691 692 reads the output of the `ls` command and puts it below the cursor. 693 694# Lesson 5 SUMMARY 695 696 1. [:!command](:!cmd) executes an external command. 697 698 Some useful examples are: 699 `:!ls`{vim} - shows a directory listing 700 `:!rm FILENAME`{vim} - removes file FILENAME 701 702 2. [:w](:w) FILENAME writes the current Vim file to disk with 703 name FILENAME. 704 705 3. [v](v) motion :w FILENAME saves the Visually selected lines in file 706 FILENAME. 707 708 4. [:r](:r) FILENAME retrieves disk file FILENAME and puts it 709 below the cursor position. 710 711 5. [:r !dir](:r!) reads the output of the dir command and 712 puts it below the cursor position. 713 714# Lesson 6.1: THE OPEN COMMAND 715 716** Type `o`{normal} to open a line below the cursor and place you in Insert mode. ** 717 718 1. Move the cursor to the line below marked ✓. 719 720 2. Type the lowercase letter `o`{normal} to [open](o) up a line BELOW the 721 cursor and place you in Insert mode. 722 723 3. Now type some text and press `<Esc>`{normal} to exit Insert mode. 724 725After typing `o`{normal} the cursor is placed on the open line in Insert mode. 726 727 4. To open up a line ABOVE the cursor, simply type a [capital O](O), rather 728 than a lowercase `o`{normal}. Try this on the line below. 729 730Open up a line above this by typing O while the cursor is on this line. 731 732# Lesson 6.2: THE APPEND COMMAND 733 734** Type `a`{normal} to insert text AFTER the cursor. ** 735 736 1. Move the cursor to the start of the line below marked ✗. 737 738 2. Press `e`{normal} until the cursor is on the end of "li". 739 740 3. Type the lowercase letter `a`{normal} to [append](a) text AFTER the cursor. 741 742 4. Complete the word like the line below it. Press `<Esc>`{normal} to exit Insert mode. 743 744 5. Use `e`{normal} to move to the next incomplete word and repeat steps 3 and 4. 745 746This li will allow you to pract appendi text to a line. 747This line will allow you to practice appending text to a line. 748 749NOTE: [a](a), [i](i) and [A](A) all go to the same Insert mode, the only 750 difference is where the characters are inserted. 751 752# Lesson 6.3: ANOTHER WAY TO REPLACE 753 754** Type a capital `R`{normal} to replace more than one character. ** 755 756 1. Move the cursor to the first line below marked ✗. Move the cursor to 757 the beginning of the first "xxx". 758 759 2. Now press `R`{normal} ([capital R](R)) and type the number below it in the 760 second line, so that it replaces the "xxx". 761 762 3. Press `<Esc>`{normal} to leave [Replace mode](mode-replace). Notice that 763 the rest of the line remains unmodified. 764 765 4. Repeat the steps to replace the remaining "xxx". 766 767Adding 123 to xxx gives you xxx. 768Adding 123 to 456 gives you 579. 769 770NOTE: Replace mode is like Insert mode, but every typed character 771 deletes an existing character. 772 773# Lesson 6.4: COPY AND PASTE TEXT 774 775** Use the `y`{normal} operator to copy text and `p`{normal} to paste it. ** 776 777 1. Go to the line marked with ✓ below and place the cursor after "a)". 778 779 2. Start Visual mode with `v`{normal} and move the cursor to just before 780 "first". 781 782 3. Type `y`{normal} to [yank](yank) (copy) the highlighted text. 783 784 4. Move the cursor to the end of the next line: `j$`{normal} 785 786 5. Type `p`{normal} to [put](put) (paste) the text. 787 788 6. Press `a`{normal} and then type "second". Press `<Esc>`{normal} to leave 789 Insert mode. 790 791 7. Use Visual mode to select "item.", yank it with `y`{normal}, move to the 792 end of the next line with `j$`{normal} and put the text there with `p`{normal} 793 794a) This is the first item. 795b) 796 797NOTE: you can use `y`{normal} as an operator: `yw`{normal} yanks one word. 798 799# Lesson 6.5: SET OPTION 800 801** Set an option so a search or substitute ignores case. ** 802 803 1. Search for 'ignore' by entering: `/ignore` 804 Repeat several times by pressing `n`{normal}. 805 806 2. Set the 'ic' (Ignore case) option by entering: 807~~~ cmd 808 :set ic 809~~~ 810 3. Now search for 'ignore' again by pressing `n`{normal}. 811 Notice that Ignore and IGNORE are now also found. 812 813 4. Set the 'hlsearch' and 'incsearch' options: 814~~~ cmd 815 :set hls is 816~~~ 817 5. Now type the search command again and see what happens: /ignore <Enter> 818 819 6. To disable ignoring case enter: 820~~~ cmd 821 :set noic 822~~~ 823 7. To toggle the value of a setting, prepend it with "inv": 824~~~ cmd 825 :set invic 826~~~ 827NOTE: To remove the highlighting of matches enter: 828~~~ cmd 829 :nohlsearch 830~~~ 831NOTE: If you want to ignore case for just one search command, use [\c](/\c) 832 in the phrase: /ignore\c <Enter> 833 834# Lesson 6 SUMMARY 835 836 1. Type `o`{normal} to open a line BELOW the cursor and start Insert mode. 837 Type `O`{normal} to open a line ABOVE the cursor. 838 839 2. Type `a`{normal} to insert text AFTER the cursor. 840 Type `A`{normal} to insert text after the end of the line. 841 842 3. The `e`{normal} command moves to the end of a word. 843 844 4. The `y`{normal} operator copies text, `p`{normal} pastes it. 845 846 5. Typing a capital `R`{normal} enters Replace mode until `<Esc>`{normal} is 847 pressed. 848 849 6. Typing "[:set](:set) xxx" sets the option "xxx". Some options are: 850 851 'ic' 'ignorecase' ignore upper/lower case when searching 852 'is' 'incsearch' show partial matches for a search phrase 853 'hls' 'hlsearch' highlight all matching phrases 854 855 You can either use the long or the short option name. 856 857 7. Prepend "no" to switch an option off: 858~~~ cmd 859 :set noic 860~~~ 861 8. Prepend "inv" to toggle an option: 862~~~ cmd 863 :set invic 864~~~ 865# Lesson 7.1: GETTING HELP 866 867** Use the on-line help system. ** 868 869Vim has a comprehensive on-line help system. 870 871To get started, try one of these three: 872 873 - press the `<HELP>`{normal} key (if you have one) 874 - press the `<F1>`{normal} key (if you have one) 875 - type `:help`{vim} 876 877Read the text in the help window to find out how the help works. 878Type `<C-w><C-w>`{normal} to jump from one window to another. 879Type `:q`{vim} to close the help window. 880 881You can find help on just about any subject, by giving an argument to the 882":help" command. Try these (don't forget pressing <Enter>): 883~~~ cmd 884 :help w 885 :help c_CTRL-D 886 :help insert-index 887 :help user-manual 888~~~ 889# Lesson 7.2: CREATE A STARTUP SCRIPT 890 891** Enable Vim features. ** 892 893Vim has many more features than Vi, but most of them are disabled by 894default. To start using more features you have to create a "vimrc" file. 895 896 1. Start editing the "vimrc" file. 897 898 `:call mkdir(stdpath('config'),'p')`{vim} 899 `:exe 'edit' stdpath('config').'/init.vim'`{vim} 900 901 2. Write the file with: 902 903 `:w`{vim} 904 905 You can add all your preferred settings to this "vimrc" file. 906 For more information type `:help vimrc-intro`{vim}. 907 908# Lesson 7.3: COMPLETION 909 910** Command line completion with `<C-d>`{normal} and `<Tab>`{normal}. ** 911 912 1. Look what files exist in the directory: `:!ls`{vim} 913 914 2. Type the start of a command: `:e`{vim} 915 916 3. Press `<C-d>`{normal} and Vim will show a list of commands beginning with "e". 917 918 4. Press `<Tab>`{normal} and Vim will complete the command name to ":edit". 919 920 5. Now add a space and the start of an existing file name: `:edit FIL`{vim} 921 922 6. Press `<Tab>`{normal}. Vim will complete the name ("FIL" -> "FILE", if it is unique). 923 924NOTE: Completion works for many commands. It is especially useful for `:help`{vim}. 925 926# Lesson 7 SUMMARY 927 928 1. Type `:help`{vim} 929 or press `<F1>`{normal} or `<Help>`{normal} to open a help window. 930 931 2. Type `:help TOPIC`{vim} to find help on TOPIC. 932 933 3. Type `<C-w><C-w>`{normal} to jump to another window 934 935 4. Type `:q`{vim} to close the help window 936 937 5. Create a vimrc startup script to keep your preferred settings. 938 939 6. While in command mode, press `<C-d>`{normal} to see possible completions. 940 Press `<Tab>`{normal} to use one completion. 941 942# CONCLUSION 943 944This was intended to give a brief overview of the Vim editor, just enough to 945allow you to use the editor fairly easily. It is far from complete as Vim has 946many many more commands. Consult the help often. 947 948There are many resources online to learn more about vim. Here's a bunch of 949them: 950 951- *Learn Vim Progressively*: 952 http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/ 953- *Learning Vim in 2013*: 954 http://benmccormick.org/learning-vim-in-2014/ 955- *Vimcasts*: 956 http://vimcasts.org/ 957- *Vim Video-Tutorials by Derek Wyatt*: 958 http://derekwyatt.org/vim/tutorials/ 959- *Learn Vimscript the Hard Way*: 960 http://learnvimscriptthehardway.stevelosh.com/ 961- *7 Habits of Effective Text Editing*: 962 http://www.moolenaar.net/habits.html 963- *vim-galore*: 964 https://github.com/mhinz/vim-galore 965 966If you prefer a book, *Practical Vim* by Drew Neil is recommended often 967(the sequel, *Modern Vim*, includes material specific to nvim). 968 969This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado 970School of Mines using ideas supplied by Charles Smith, Colorado State 971University. E-mail: bware@mines.colorado.edu. 972 973Modified for Vim by Bram Moolenaar. 974Modified for vim-tutor-mode by Felipe Morales. 975 976// vim: nowrap 977