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