vim-01-beginner.tutor 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996
  1. # Welcome to the Neovim Tutorial
  2. Neovim is a very powerful editor that has many commands, too many to explain in
  3. a tutorial such as this. This tutorial is designed to describe enough of the
  4. commands that you will be able to easily use Neovim as an all-purpose editor.
  5. It is IMPORTANT to remember that this tutorial is set up to teach by use. That
  6. means that you need to do the exercises to learn them properly. If you only
  7. read the text, you will soon forget what is most important!
  8. For now, make sure that your Caps-Lock is off and press the `j`{normal} key enough
  9. times to move the cursor so that Lesson 0 completely fills the screen.
  10. # Lesson 0
  11. NOTE: The commands in the lessons will modify the text, but those changes
  12. won't be saved. Don't worry about messing things up; just remember that
  13. pressing [<Esc>](<Esc>) and then [u](u) will undo the latest change.
  14. This tutorial is interactive, and there are a few things you should know.
  15. - Type [<Enter>](<Enter>) on links [like this](holy-grail ) to open the linked help section.
  16. - Or simply type [K](K) on any word to find its documentation!
  17. - You can close this help window with `:q`{vim} `<Enter>`{normal}
  18. When there is a ✗ sign at the left, you will be required to modify text.
  19. Once you have done the changes correctly, the ✗ sign at the left will change
  20. to ✓. I imagine you can already see how neat Neovim can be.
  21. Other times, you'll be prompted to run a command (I'll explain this later):
  22. `:help`{vim} `<Enter>`{normal}
  23. or press a sequence of keys
  24. ~~~ normal
  25. <Esc>0f<Space>d3wP$P
  26. ~~~
  27. Text within <'s and >'s (like `<Enter>`{normal}) describes a key to press
  28. instead of text to type.
  29. Now, move to the next lesson (use the `j`{normal} key to scroll down).
  30. # Lesson 1.1: MOVING THE CURSOR
  31. ** To move the cursor, press the `h`, `j`, `k`, `l` keys as indicated. **
  32. k Hint: The `h`{normal} key is at the left and moves left.
  33. ← h l → The `l`{normal} key is at the right and moves right.
  34. j The `j`{normal} key looks like a down arrow.
  35. 1. Move the cursor around the screen until you are comfortable.
  36. 2. Hold down the down key (`j`{normal}) until it repeats.
  37. Now you know how to move to the next lesson.
  38. 3. Using the down key, move to Lesson 1.2.
  39. NOTE: If you are ever unsure about something you typed, press <Esc> to place
  40. you in Normal mode. Then retype the command you wanted.
  41. NOTE: The cursor keys should also work. But using hjkl you will be able to
  42. move around much faster, once you get used to it.
  43. # Lesson 1.2: EXITING NEOVIM
  44. !! NOTE: Before executing any of the steps below, read the entire lesson !!
  45. 1. Press the <Esc> key (to make sure you are in Normal mode).
  46. 2. Type:
  47. `:q!`{vim} `<Enter>`{normal}
  48. This quits the editor, DISCARDING any changes you have made.
  49. 3. Open Neovim and get back here by executing the command that got you into
  50. this tutorial. That might be:
  51. `:Tutor`{vim} `<Enter>`{normal}
  52. 4. If you have these steps memorized and are confident, execute steps
  53. 1 through 3 to exit and re-enter the editor.
  54. NOTE: [:q!](:q) `<Enter>`{normal} discards any changes you made. In a few lessons you
  55. will learn how to save the changes to a file.
  56. 5. Move the cursor down to Lesson 1.3.
  57. # Lesson 1.3: TEXT EDITING: DELETION
  58. ** Press `x`{normal} to delete the character under the cursor. **
  59. 1. Move the cursor to the line below marked ✗.
  60. 2. To fix the errors, move the cursor until it is on top of the
  61. character to be deleted.
  62. 3. Press [the x key](x) to delete the unwanted character.
  63. 4. Repeat steps 2 through 4 until the sentence is correct.
  64. The ccow jumpedd ovverr thhe mooon.
  65. 5. Now that the line is correct, go on to Lesson 1.4.
  66. NOTE: As you go through this tutorial, do not try to memorize everything,
  67. your Neovim vocabulary will expand with usage. Consider returning to
  68. this tutorial periodically for a refresher.
  69. # Lesson 1.4: TEXT EDITING: INSERTION
  70. ** Press `i`{normal} to insert text. **
  71. 1. Move the cursor to the first line below marked ✗.
  72. 2. To make the first line the same as the second, move the cursor on top
  73. of the first character AFTER where the text is to be inserted.
  74. 3. Press `i`{normal} and type in the necessary additions.
  75. 4. As each error is fixed press `<Esc>`{normal} to return to Normal mode.
  76. Repeat steps 2 through 4 to correct the sentence.
  77. There is text misng this .
  78. There is some text missing from this line.
  79. 5. When you are comfortable inserting text move to Lesson 1.5.
  80. # Lesson 1.5: TEXT EDITING: APPENDING
  81. ** Press `A`{normal} to append text. **
  82. 1. Move the cursor to the first line below marked ✗.
  83. It does not matter on what character the cursor is in that line.
  84. 2. Press [A](A) and type in the necessary additions.
  85. 3. As the text has been appended press `<Esc>`{normal} to return to Normal
  86. mode.
  87. 4. Move the cursor to the second line marked ✗ and repeat
  88. steps 2 and 3 to correct this sentence.
  89. There is some text missing from th
  90. There is some text missing from this line.
  91. There is also some text miss
  92. There is also some text missing here.
  93. 5. When you are comfortable appending text move to Lesson 1.6.
  94. # Lesson 1.6: EDITING A FILE
  95. ** Use `:wq`{vim} to write a file and quit. **
  96. !! NOTE: Before executing any of the steps below, read the entire lesson !!
  97. 1. Exit this tutorial as you did in Lesson 1.2: `:q!`{vim}
  98. Or, if you have access to another terminal, do the following there.
  99. 2. At the shell prompt type this command:
  100. ~~~ sh
  101. $ nvim tutor
  102. ~~~
  103. 'nvim' is the command to start the Nvim editor, 'tutor' is the name of
  104. the file you wish to edit. Use a file that may be changed.
  105. 3. Insert and delete text as you learned in the previous lessons.
  106. 4. Save the file with changes and exit Neovim with:
  107. ~~~ cmd
  108. :wq
  109. ~~~
  110. Note you'll need to press `<Enter>` to execute the command.
  111. 5. If you have quit this tutorial in step 1, restart and move down
  112. to the following summary.
  113. 6. After reading and understanding the above steps: do them.
  114. # Lesson 1 SUMMARY
  115. 1. The cursor is moved using either the arrow keys or the hjkl keys.
  116. h (left) j (down) k (up) l (right)
  117. 2. To start Neovim from the shell prompt type:
  118. ~~~ sh
  119. $ nvim FILENAME
  120. ~~~
  121. 3. To exit Neovim type: `<Esc>`{normal} `:q!`{vim} `<Enter>`{normal} to trash all changes.
  122. OR type: `<Esc>`{normal} `:wq`{vim} `<Enter>`{normal} to save the changes.
  123. 4. To delete the character at the cursor type: `x`{normal}
  124. 5. To insert or append text type:
  125. `i`{normal} insert text `<Esc>`{normal} insert before the cursor.
  126. `A`{normal} append text `<Esc>`{normal} append after the line.
  127. NOTE: Pressing `<Esc>`{normal} will place you in Normal mode or will cancel
  128. an unwanted and partially completed command.
  129. Now continue with Lesson 2.
  130. # Lesson 2.1: DELETION COMMANDS
  131. ** Type `dw`{normal} to delete a word. **
  132. 1. Press `<Esc>`{normal} to make sure you are in Normal mode.
  133. 2. Move the cursor to the line below marked ✗.
  134. 3. Move the cursor to the beginning of a word that needs to be deleted.
  135. 4. Type [d](d)[w](w) to make the word disappear.
  136. There are a some words fun that don't belong paper in this sentence.
  137. 5. Repeat steps 3 and 4 until the sentence is correct and go to Lesson 2.2.
  138. # Lesson 2.2: MORE DELETION COMMANDS
  139. ** Type `d$`{normal} to delete to the end of the line. **
  140. 1. Press `<Esc>`{normal} to make sure you are in Normal mode.
  141. 2. Move the cursor to the line below marked ✗.
  142. 3. Move the cursor to the end of the correct line (AFTER the first . ).
  143. 4. Type `d$`{normal} to delete to the end of the line.
  144. Somebody typed the end of this line twice. end of this line twice.
  145. 5. Move on to Lesson 2.3 to understand what is happening.
  146. # Lesson 2.3: ON OPERATORS AND MOTIONS
  147. Many commands that change text are made from an [operator](operator) and a [motion](navigation).
  148. The format for a delete command with the [d](d) delete operator is as follows:
  149. d motion
  150. Where:
  151. d - is the delete operator.
  152. motion - is what the operator will operate on (listed below).
  153. A short list of motions:
  154. [w](w) - until the start of the next word, EXCLUDING its first character.
  155. [e](e) - to the end of the current word, INCLUDING the last character.
  156. [$]($) - to the end of the line, INCLUDING the last character.
  157. Thus typing `de`{normal} will delete from the cursor to the end of the word.
  158. NOTE: Pressing just the motion while in Normal mode without an operator
  159. will move the cursor as specified.
  160. # Lesson 2.4: USING A COUNT FOR A MOTION
  161. ** Typing a number before a motion repeats it that many times. **
  162. 1. Move the cursor to the start of the line marked ✓ below.
  163. 2. Type `2w`{normal} to move the cursor two words forward.
  164. 3. Type `3e`{normal} to move the cursor to the end of the third word forward.
  165. 4. Type `0`{normal} ([zero](0)) to move to the start of the line.
  166. 5. Repeat steps 2 and 3 with different numbers.
  167. This is just a line with words you can move around in.
  168. 6. Move on to Lesson 2.5.
  169. # Lesson 2.5: USING A COUNT TO DELETE MORE
  170. ** Typing a number with an operator repeats it that many times. **
  171. In the combination of the delete operator and a motion mentioned above you
  172. insert a count before the motion to delete more:
  173. d number motion
  174. 1. Move the cursor to the first UPPER CASE word in the line marked ✗.
  175. 2. Type `d2w`{normal} to delete the two UPPER CASE words
  176. 3. Repeat steps 1 and 2 with a different count to delete the consecutive
  177. UPPER CASE words with one command
  178. This ABC DE line FGHI JK LMN OP of words is Q RS TUV cleaned up.
  179. # Lesson 2.6: OPERATING ON LINES
  180. ** Type `dd`{normal} to delete a whole line. **
  181. Due to the frequency of whole line deletion, the designers of Vi decided
  182. it would be easier to simply type two d's to delete a line.
  183. 1. Move the cursor to the second line in the phrase below.
  184. 2. Type [dd](dd) to delete the line.
  185. 3. Now move to the fourth line.
  186. 4. Type `2dd`{normal} to delete two lines, then press `u`{normal} twice to undo all three lines.
  187. 1) Roses are red,
  188. 2) Mud is fun,
  189. 3) Violets are blue,
  190. 4) I have a car,
  191. 5) Clocks tell time,
  192. 6) Sugar is sweet
  193. 7) And so are you.
  194. # Lesson 2.7: THE UNDO COMMAND
  195. ** Press `u`{normal} to undo the last commands, `U`{normal} to fix a whole line. **
  196. 1. Move the cursor to the line below marked ✗ and place it on the first error.
  197. 2. Type `x`{normal} to delete the first unwanted character.
  198. 3. Now type `u`{normal} to undo the last command executed.
  199. 4. This time fix all the errors on the line using the `x`{normal} command.
  200. 5. Now type a capital `U`{normal} to return the line to its original state.
  201. 6. Now type `u`{normal} a few times to undo the `U`{normal} and preceding commands.
  202. 7. Now type `<C-r>`{normal} (Control + R) a few times to redo the commands.
  203. Fiix the errors oon thhis line and reeplace them witth undo.
  204. 8. These are very useful commands. Now move on to the Lesson 2 Summary.
  205. # Lesson 2 SUMMARY
  206. 1. To delete from the cursor up to the next word type: `dw`{normal}
  207. 2. To delete from the cursor to the end of a line type: `d$`{normal}
  208. 3. To delete a whole line type: `dd`{normal}
  209. 4. To repeat a motion prepend it with a number: `2w`{normal}
  210. 5. The format for a change command is:
  211. operator [number] motion
  212. where:
  213. operator - is what to do, such as [d](d) for delete
  214. [number] - is an optional count to repeat the motion
  215. motion - moves over the text to operate on, such as:
  216. [w](w) (word),
  217. [$]($) (to the end of line), etc.
  218. 6. To move to the start of the line use a zero: [0](0)
  219. 7. To undo previous actions, type: `u`{normal} (lowercase u)
  220. To undo all the changes on a line, type: `U`{normal} (capital U)
  221. To undo the undos, type: `<C-r>`{normal}
  222. # Lesson 3.1: THE PUT COMMAND
  223. ** Type `p`{normal} to put previously deleted text after the cursor. **
  224. 1. Move the cursor to the first ✓ line below.
  225. 2. Type `dd`{normal} to delete the line and store it in a Neovim register.
  226. 3. Move the cursor to the c) line, ABOVE where the deleted line should go.
  227. 4. Type `p`{normal} to put the line below the cursor.
  228. 5. Repeat steps 2 through 4 to put all the lines in correct order.
  229. d) Can you learn too?
  230. b) Violets are blue,
  231. c) Intelligence is learned,
  232. a) Roses are red,
  233. NOTE: You can also put the text before the cursor with `P`{normal} (capital P).
  234. # Lesson 3.2: THE REPLACE COMMAND
  235. ** Type `rx`{normal} to replace the character at the cursor with x. **
  236. 1. Move the cursor to the first line below marked ✗.
  237. 2. Move the cursor so that it is on top of the first error.
  238. 3. Type `r`{normal} and then the character which should be there.
  239. 4. Repeat steps 2 and 3 until the first line is equal to the second one.
  240. Whan this lime was tuoed in, someone presswd some wrojg keys!
  241. When this line was typed in, someone pressed some wrong keys!
  242. 5. Now move on to Lesson 3.3.
  243. NOTE: Remember that you should be learning by doing, not memorizing.
  244. # Lesson 3.3: THE CHANGE OPERATOR
  245. ** To change until the end of a word, type `ce`{normal}. **
  246. 1. Move the cursor to the first line below marked ✗.
  247. 2. Place the cursor on the "u" in "lubw".
  248. 3. Type `ce`{normal} and the correct word (in this case, type "ine" ).
  249. 4. Press `<Esc>`{normal} and move to the next character that needs to be changed.
  250. 5. Repeat steps 3 and 4 until the first sentence is the same as the second.
  251. This lubw has a few wptfd that mrrf changing usf the change operator.
  252. This line has a few words that need changing using the change operator.
  253. Notice that [c](c)e deletes the word and places you in Insert mode.
  254. # Lesson 3.4: MORE CHANGES USING `c`{normal}
  255. ** The change operator is used with the same motions as delete. **
  256. 1. The change operator works in the same way as delete. The format is:
  257. c [number] motion
  258. 2. The motions are the same, such as `w`{normal} (word) and `$`{normal} (end of line).
  259. 3. Move to the first line below marked ✗.
  260. 4. Move the cursor to the first error.
  261. 5. Type `c$`{normal} and type the rest of the line like the second and press `<Esc>`{normal}.
  262. The end of this line needs some help to make it like the second.
  263. The end of this line needs to be corrected using the c$ command.
  264. NOTE: You can use the Backspace key to correct mistakes while typing.
  265. # Lesson 3 SUMMARY
  266. 1. To put back text that has just been deleted, type [p](p). This puts the
  267. deleted text AFTER the cursor (if a line was deleted it will go on the
  268. line below the cursor).
  269. 2. To replace the character under the cursor, type [r](r) and then the
  270. character you want to have there.
  271. 3. The [change operator](c) allows you to change from the cursor to where
  272. the motion takes you. Type `ce`{normal} to change from the cursor to the
  273. end of the word, `c$`{normal} to change to the end of a line, etc.
  274. 4. The format for change is:
  275. c [number] motion
  276. Now go on to the next lesson.
  277. # Lesson 4.1: CURSOR LOCATION AND FILE STATUS
  278. ** Type `<C-g>`{normal} to show your location in a file and the file status.
  279. Type `G`{normal} to move to a line in the file. **
  280. NOTE: Read the entire lesson before executing any of these steps!!
  281. 1. Hold down the `<Ctrl>`{normal} key and press `g`{normal}. We call this `<C-g>`{normal}.
  282. A message will appear at the bottom of the page with the filename and
  283. the position in the file. Remember the line number for Step 3.
  284. NOTE: You may see the cursor position in the lower right corner of the
  285. screen. This happens when the ['ruler']('ruler') option is set.
  286. 2. Press [G](G) to move you to the bottom of the file.
  287. Type [gg](gg) to move you to the start of the file.
  288. 3. Type the number of the line you were on and then `G`{normal}. This will
  289. return you to the line you were on when you first pressed `<C-g>`{normal}.
  290. 4. If you feel confident to do this, execute steps 1 through 3.
  291. # Lesson 4.2: THE SEARCH COMMAND
  292. ** Type `/`{normal} followed by a phrase to search for the phrase. **
  293. 1. In Normal mode type the `/`{normal} character. Notice that it and the
  294. cursor appear at the bottom of the screen as with the `:`{normal} command.
  295. 2. Now type 'errroor' `<Enter>`{normal}. This is the word you want to search for.
  296. 3. To search for the same phrase again, simply type [n](n).
  297. To search for the same phrase in the opposite direction, type [N](N).
  298. 4. To search for a phrase in the backward direction, use [?](?) instead of `/`{normal}.
  299. 5. To go back to where you came from press `<C-o>`{normal}.
  300. (keep `<Ctrl>`{normal} pressed down while pressing the letter `o`{normal}).
  301. Repeat to go back further. `<C-i>`{normal} goes forward.
  302. "errroor" is not the way to spell error; errroor is an error.
  303. NOTE: When the search reaches the end of the file it will continue at the
  304. start, unless the ['wrapscan']('wrapscan') option has been reset.
  305. # Lesson 4.3: MATCHING PARENTHESES SEARCH
  306. ** Type `%`{normal} to find a matching ), ], or }. **
  307. 1. Place the cursor on any (, [, or { in the line below marked ✓.
  308. 2. Now type the [%](%) character.
  309. 3. The cursor will move to the matching parenthesis or bracket.
  310. 4. Type `%`{normal} to move the cursor to the other matching bracket.
  311. 5. Move the cursor to another (, ), [, ], {, or } and see what `%`{normal} does.
  312. This ( is a test line with ('s, ['s, ] and {'s } in it. ))
  313. NOTE: This is very useful in debugging a program with unmatched parentheses!
  314. # Lesson 4.4: THE SUBSTITUTE COMMAND
  315. ** Type `:s/old/new/g` to substitute "new" for "old". **
  316. 1. Move the cursor to the line below marked ✗.
  317. 2. Type
  318. ~~~ cmd
  319. :s/thee/the/
  320. ~~~
  321. NOTE: The [:s](:s) command only changed the first match of "thee" in the line.
  322. 3. Now type
  323. ~~~ cmd
  324. :s/thee/the/g
  325. ~~~
  326. Adding the g [flag](:s_flags) means to substitute globally in the line,
  327. change all occurrences of "thee" in the line.
  328. Usually thee best time to see thee flowers is in thee spring.
  329. 4. To change every occurrence of a character string between two lines, type
  330. ~~~ cmd
  331. :#,#s/old/new/g
  332. ~~~
  333. where # are the line numbers of the range of lines where the
  334. substitution is to be done (i.e., `1,3` means from line 1 to line 3, inclusive).
  335. Type
  336. ~~~ cmd
  337. :%s/old/new/g
  338. ~~~
  339. to change every occurrence in the whole file.
  340. Type
  341. ~~~ cmd
  342. :%s/old/new/gc
  343. ~~~
  344. to find every occurrence in the whole file, with a prompt whether to
  345. substitute or not.
  346. NOTE: You can also select the lines you want to substitute first using Visual mode.
  347. This will be explained more in a future lesson.
  348. # Lesson 4 SUMMARY
  349. 1. `<C-g>`{normal} displays your location and the file status.
  350. `G`{normal} moves to the end of the file.
  351. number `G`{normal} moves to that line number.
  352. `gg`{normal} moves to the first line.
  353. 2. Typing `/`{normal} followed by a phrase searches FORWARD for the phrase.
  354. Typing `?`{normal} followed by a phrase searches BACKWARD for the phrase.
  355. After a search type `n`{normal} to find the next occurrence in the same
  356. direction or `N`{normal} to search in the opposite direction.
  357. `<C-o>`{normal} takes you back to older positions, `<C-i>`{normal} to
  358. newer positions.
  359. 3. Typing `%`{normal} while the cursor is on a (, ), [, ], {, or } goes to its
  360. match.
  361. 4. To substitute new for the first old in a line type
  362. ~~~ cmd
  363. :s/old/new
  364. ~~~
  365. To substitute new for all olds on a line type
  366. ~~~ cmd
  367. :s/old/new/g
  368. ~~~
  369. To substitute phrases between two line #'s type
  370. ~~~ cmd
  371. :#,#s/old/new/g
  372. ~~~
  373. To substitute all occurrences in the file type
  374. ~~~ cmd
  375. :%s/old/new/g
  376. ~~~
  377. To ask for confirmation each time add 'c'
  378. ~~~ cmd
  379. :%s/old/new/gc
  380. ~~~
  381. # Lesson 5.1: HOW TO EXECUTE AN EXTERNAL COMMAND
  382. ** Type `:!`{vim} followed by an external command to execute that command. **
  383. 1. Type the familiar command `:`{normal} to set the cursor at the bottom of
  384. the screen. This allows you to enter a command-line command.
  385. 2. Now type the [!](!cmd) (exclamation point) character. This allows you to
  386. execute any external shell command.
  387. 3. As an example type "ls" following the "!" and then hit `<Enter>`{normal}.
  388. This will show you a listing of your directory, just as if you were
  389. at the shell prompt.
  390. NOTE: It is possible to execute any external command this way, and you
  391. can include arguments.
  392. NOTE: All `:`{vim} commands are executed when you press `<Enter>`{normal}.
  393. # Lesson 5.2: MORE ON WRITING FILES
  394. ** To save the changes made to the text, type `:w`{vim} FILENAME. **
  395. 1. Type `:!{unix:(ls),win:(dir)}`{vim} to get a listing of your directory.
  396. You already know you must hit `<Enter>`{normal} after this.
  397. 2. Choose a filename that does not exist yet, such as TEST.
  398. 3. Now type:
  399. ~~~ cmd
  400. :w TEST
  401. ~~~
  402. (where TEST is the filename you chose.)
  403. 4. This saves the current file under the name TEST.
  404. To verify this, type `:!{unix:(ls),win:(dir)}`{vim} again to see your directory.
  405. NOTE: If you were to exit Neovim and start it again with `nvim TEST`, the file
  406. would be an exact copy of the tutorial when you saved it.
  407. 5. Now remove the file by typing:
  408. ~~~ cmd
  409. :!{unix:(rm),win:(del)} TEST
  410. ~~~
  411. # Lesson 5.3: SELECTING TEXT TO WRITE
  412. ** To save part of the file, type `v`{normal} motion `:w FILENAME`{vim}. **
  413. 1. Move the cursor to this line.
  414. 2. Press [v](v) and move the cursor to the fifth item below. Notice that the
  415. text is highlighted.
  416. 3. Press the `:`{normal} character. At the bottom of the screen
  417. `:'<,'>`{vim}
  418. will appear.
  419. 4. Type
  420. `w TEST`{vim}
  421. where TEST is a filename that does not exist yet. Verify that you see
  422. `:'<,'>w TEST`{vim}
  423. before you press `<Enter>`{normal}.
  424. 5. Neovim will write the selected lines to the file TEST. Use `:!{unix:(ls),win:(dir)}`{vim} to see it.
  425. Do not remove it yet! We will use it in the next lesson.
  426. NOTE: Pressing [v](v) starts [Visual selection](visual-mode). You can move the cursor around to
  427. make the selection bigger or smaller. Then you can use an operator to
  428. do something with the text. For example, `d`{normal} deletes the text.
  429. # Lesson 5.4: RETRIEVING AND MERGING FILES
  430. ** To retrieve the contents of a file, type `:r FILENAME`{vim}. **
  431. 1. Place the cursor just above this line.
  432. NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move
  433. DOWN to see this lesson again. Press `u`{normal} to undo after you are done.
  434. 2. Now retrieve your TEST file using the command
  435. `:r TEST`{vim}
  436. where TEST is the name of the file you used.
  437. The file you retrieve is placed below the cursor line.
  438. 3. To verify that a file was retrieved, cursor back and notice that there
  439. are now two copies of Lesson 5.3, the original and the retrieved version.
  440. NOTE: You can also read the output of an external command. For example,
  441. `:r !{unix:(ls),win:(dir)}`{vim}
  442. reads the output of the `ls` command and puts it below the cursor.
  443. # Lesson 5 SUMMARY
  444. 1. [:!command](:!cmd) executes an external command.
  445. Some useful examples are:
  446. `:!{unix:(ls ),win:(dir)}`{vim} - shows a directory listing
  447. `:!{unix:(rm ),win:(del)} FILENAME`{vim} - removes file FILENAME
  448. 2. [:w](:w) FILENAME writes the current Neovim file to disk with
  449. name FILENAME.
  450. 3. [v](v) motion :w FILENAME saves the Visually selected lines in file
  451. FILENAME.
  452. 4. [:r](:r) FILENAME retrieves disk file FILENAME and puts it
  453. below the cursor position.
  454. 5. {unix:([:r !ls](:r!) ),win:([:r !dir](:r!))} reads the output of the {unix:(ls),win:(dir)} command and
  455. puts it below the cursor position.
  456. # Lesson 6.1: THE OPEN COMMAND
  457. ** Type `o`{normal} to open a line below the cursor and place you in Insert mode. **
  458. 1. Move the cursor to the line below marked ✓.
  459. 2. Type the lowercase letter `o`{normal} to [open](o) up a line BELOW the
  460. cursor and place you in Insert mode.
  461. 3. Now type some text and press `<Esc>`{normal} to exit Insert mode. Remove your opened lines after you're done.
  462. After typing `o`{normal} the cursor is placed on the open line in Insert mode.
  463. 4. To open up a line ABOVE the cursor, simply type a [capital O](O), rather
  464. than a lowercase `o`{normal}. Try this on the line below. Remove your opened lines after you're done.
  465. Open up a line above this by typing O while the cursor is on this line.
  466. # Lesson 6.2: THE APPEND COMMAND
  467. ** Type `a`{normal} to insert text AFTER the cursor. **
  468. 1. Move the cursor to the start of the line below marked ✗.
  469. 2. Press `e`{normal} until the cursor is on the end of "li".
  470. 3. Type the lowercase letter `a`{normal} to [append](a) text AFTER the cursor.
  471. 4. Complete the word like the line below it. Press `<Esc>`{normal} to exit Insert mode.
  472. 5. Use `e`{normal} to move to the next incomplete word and repeat steps 3 and 4.
  473. This li will allow you to pract appendi text to a line.
  474. This line will allow you to practice appending text to a line.
  475. NOTE: [a](a), [i](i), and [A](A) all go to the same Insert mode, the only
  476. difference is where the characters are inserted.
  477. # Lesson 6.3: ANOTHER WAY TO REPLACE
  478. ** Type a capital `R`{normal} to replace more than one character. **
  479. 1. Move the cursor to the first line below marked ✗. Move the cursor to
  480. the beginning of the first "xxx".
  481. 2. Now press `R`{normal} ([capital R](R)) and type the number below it in the
  482. second line, so that it replaces the "xxx".
  483. 3. Press `<Esc>`{normal} to leave [Replace mode](mode-replace). Notice that
  484. the rest of the line remains unmodified.
  485. 4. Repeat the steps to replace the remaining "xxx".
  486. Adding 123 to xxx gives you xxx.
  487. Adding 123 to 456 gives you 579.
  488. NOTE: Replace mode is like Insert mode, but every typed character
  489. replaces an existing character.
  490. # Lesson 6.4: COPY AND PASTE TEXT
  491. ** Use the `y`{normal} operator to copy text and `p`{normal} to put it. **
  492. 1. Go to the line marked with ✓ below and place the cursor after "a)".
  493. 2. Start Visual mode with `v`{normal} and move the cursor to just before
  494. "first".
  495. 3. Type `y`{normal} to [yank](yank) (copy) the highlighted text.
  496. 4. Move the cursor to the end of the next line: `j$`{normal}
  497. 5. Type `p`{normal} to [put](put) (paste) the text.
  498. 6. Press `a`{normal} and then type "second". Press `<Esc>`{normal} to leave
  499. Insert mode.
  500. 7. Use Visual mode to select "item.", yank it with `y`{normal}, move to the
  501. end of the next line with `j$`{normal} and put the text there with `p`{normal}
  502. a) This is the first item.
  503. b)
  504. NOTE: You can use `y`{normal} as an operator: `yw`{normal} yanks one word.
  505. NOTE: You can use `P`{normal} to put before the cursor, rather than after.
  506. # Lesson 6.5: SET OPTION
  507. ** Set an option so search and substitute commands ignore case. **
  508. There are many settings in Neovim that you can configure to suit your needs.
  509. 1. Search for 'ignore' by entering: `/ignore`
  510. Repeat several times by pressing `n`{normal}.
  511. 2. Set the 'ic' (Ignore case) option by entering:
  512. ~~~ cmd
  513. :set ic
  514. ~~~
  515. 3. Now search for 'ignore' again by pressing `n`{normal}.
  516. Notice that Ignore and IGNORE are now also found.
  517. 4. Set the 'hlsearch' and 'incsearch' options:
  518. ~~~ cmd
  519. :set hls is
  520. ~~~
  521. 5. Now type the search command again and see what happens: /ignore <Enter>
  522. 6. To disable ignoring case enter:
  523. ~~~ cmd
  524. :set noic
  525. ~~~
  526. 7. To invert the value of a setting, prepend it with "inv":
  527. ~~~ cmd
  528. :set invic
  529. ~~~
  530. NOTE: To remove the highlighting of matches enter:
  531. ~~~ cmd
  532. :nohlsearch
  533. ~~~
  534. NOTE: If you want to ignore case for just one search command, use [\c](/\c)
  535. in the phrase: /ignore\c <Enter>
  536. # Lesson 6 SUMMARY
  537. 1. Type `o`{normal} to open a line BELOW the cursor and start Insert mode.
  538. Type `O`{normal} to open a line ABOVE the cursor.
  539. 2. Type `a`{normal} to insert text AFTER the cursor.
  540. Type `A`{normal} to insert text after the end of the line.
  541. 3. The `e`{normal} command moves to the end of a word.
  542. 4. The `y`{normal} operator copies text, `p`{normal} pastes it.
  543. 5. Typing a capital `R`{normal} enters Replace mode until `<Esc>`{normal} is
  544. pressed.
  545. 6. Typing "[:set](:set) xxx" sets the option "xxx". Some options are:
  546. 'ic' 'ignorecase' ignore upper/lower case when searching
  547. 'is' 'incsearch' show partial matches for a search phrase
  548. 'hls' 'hlsearch' highlight all matching phrases
  549. You can either use the long or the short option name.
  550. 7. Prepend "no" to switch an option off:
  551. ~~~ cmd
  552. :set noic
  553. ~~~
  554. 8. Prepend "inv" to invert an option:
  555. ~~~ cmd
  556. :set invic
  557. ~~~
  558. # Lesson 7.1: GETTING HELP
  559. ** Use the online help system. **
  560. Neovim has a comprehensive online help system.
  561. To get started, try one of these two:
  562. - press the `<F1>`{normal} key (if you have one)
  563. - type `:help`{vim}
  564. Read the text in the help window to find out how the help works.
  565. Type `<C-w><C-w>`{normal} to jump from one window to another.
  566. Type `:q`{vim} to close the help window.
  567. You can find help on just about any subject, by giving an argument to the
  568. ":help" command. Try these (don't forget to press <Enter>):
  569. ~~~ cmd
  570. :help w
  571. :help c_CTRL-D
  572. :help insert-index
  573. :help user-manual
  574. ~~~
  575. # Lesson 7.2: CREATE A STARTUP SCRIPT
  576. ** Enable Neovim features. **
  577. Neovim is a very configurable editor. You can customise it any way you like.
  578. To start using more features create an "init.vim" file.
  579. 1. Start editing the "init.vim" file.
  580. `:call mkdir(stdpath('config'),'p')`{vim}
  581. `:exe 'edit' stdpath('config').'/init.vim'`{vim}
  582. 2. Write the file with:
  583. `:w`{vim}
  584. You can add all your preferred settings to this "init.vim" file.
  585. For more information type `:help init.vim`{vim}.
  586. # Lesson 7.3: COMPLETION
  587. ** Command line completion with `<C-d>`{normal} and `<Tab>`{normal}. **
  588. 1. List the contents of the current directory: `:!{unix:(ls),win:(dir)}`{vim}
  589. 2. Type the start of a command: `:e`{vim}
  590. 3. Press `<C-d>`{normal} and Neovim will show a list of commands beginning with "e".
  591. 4. Press `<Tab>`{normal} and Neovim will complete the command name to ":edit".
  592. 5. Now add a space and the start of an existing file name: `:edit FIL`{vim}
  593. 6. Press `<Tab>`{normal}. Neovim will complete the name ("FIL" -> "FILE", if it is unique).
  594. NOTE: Completion works for many commands. It is especially useful for `:help`{vim}.
  595. # Lesson 7 SUMMARY
  596. 1. Type `:help`{vim}
  597. or press `<F1>`{normal} or `<Help>`{normal} to open a help window.
  598. 2. Type `:help TOPIC`{vim} to find help on TOPIC.
  599. 3. Type `<C-w><C-w>`{normal} to jump to another window
  600. 4. Type `:q`{vim} to close the help window
  601. 5. Create an init.vim startup script to keep your preferred settings.
  602. 6. While in command mode, press `<C-d>`{normal} to see possible completions.
  603. Press `<Tab>`{normal} to use one completion.
  604. # CONCLUSION
  605. This was intended to give a brief overview of the Neovim editor, just enough to
  606. allow you to use it fairly easily. It is far from complete as Neovim has
  607. many many more commands. Consult the help often.
  608. There are also countless great tutorials and videos to be found online.
  609. Here's a bunch of them:
  610. - *Learn Vim Progressively*:
  611. https://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
  612. - *Learning Vim in 2014*:
  613. https://benmccormick.org/learning-vim-in-2014/
  614. - *Vimcasts*:
  615. http://vimcasts.org/
  616. - *Vim Video-Tutorials by Derek Wyatt*:
  617. http://derekwyatt.org/vim/tutorials/
  618. - *Learn Vimscript the Hard Way*:
  619. https://learnvimscriptthehardway.stevelosh.com/
  620. - *7 Habits of Effective Text Editing*:
  621. https://www.moolenaar.net/habits.html
  622. - *vim-galore*:
  623. https://github.com/mhinz/vim-galore
  624. If you prefer a book, *Practical Vim* by Drew Neil is recommended often
  625. (the sequel, *Modern Vim*, includes material specific to Neovim).
  626. This tutorial was written by Michael C. Pierce and Robert K. Ware, Colorado
  627. School of Mines using ideas supplied by Charles Smith, Colorado State
  628. University. E-mail: bware@mines.colorado.edu.
  629. Modified for Vim by Bram Moolenaar.
  630. Modified for vim-tutor-mode by Felipe Morales.
  631. Modified for Neovim by Rory Nesbitt.
  632. // vim: nowrap