neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

vim-01-beginner.tutor (33547B)


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