forked from aniani/vim
runtime(new-tutor): add chapter two to the interactive tutorial
closes: #16803 Signed-off-by: RestorerZ <restorer@mail2k.ru> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
parent
34a7d82aae
commit
2323f225ca
14
Filelist
14
Filelist
@ -771,16 +771,16 @@ RT_ALL = \
|
||||
runtime/tools/[a-z]*[a-z0-9] \
|
||||
runtime/tutor/README.txt \
|
||||
runtime/tutor/tutor1 \
|
||||
runtime/tutor/tutor1.utf-8 \
|
||||
runtime/tutor/en/vim-01-beginner.tutor \
|
||||
runtime/tutor/en/vim-01-beginner.tutor.json \
|
||||
runtime/tutor/it/vim-01-beginner.tutor \
|
||||
runtime/tutor/it/vim-01-beginner.tutor.json \
|
||||
runtime/tutor/sr/vim-01-beginner.tutor \
|
||||
runtime/tutor/sr/vim-01-beginner.tutor.json \
|
||||
runtime/tutor/en/vim-02-beginner.tutor \
|
||||
runtime/tutor/en/vim-02-beginner.tutor.json \
|
||||
runtime/tutor/tutor.tutor \
|
||||
runtime/tutor/tutor.tutor.json \
|
||||
runtime/tutor/tutor.vim \
|
||||
runtime/tutor/tutor2 \
|
||||
runtime/tutor/tutor2.utf-8 \
|
||||
runtime/vimrc_example.vim \
|
||||
runtime/pack/dist/opt/cfilter/plugin/cfilter.vim \
|
||||
runtime/pack/dist/opt/comment/plugin/comment.vim \
|
||||
@ -1077,7 +1077,10 @@ LANG_GEN = \
|
||||
runtime/tutor/README.*.txt \
|
||||
runtime/tutor/Makefile \
|
||||
runtime/tutor/Make_all.mak \
|
||||
runtime/tutor/tutor1.utf-8 \
|
||||
runtime/tutor/it/vim-01-beginner.tutor \
|
||||
runtime/tutor/it/vim-01-beginner.tutor.json \
|
||||
runtime/tutor/sr/vim-01-beginner.tutor \
|
||||
runtime/tutor/sr/vim-01-beginner.tutor.json \
|
||||
runtime/tutor/tutor1.?? \
|
||||
runtime/tutor/tutor1.??.utf-8 \
|
||||
runtime/tutor/tutor1.??.euc \
|
||||
@ -1090,7 +1093,6 @@ LANG_GEN = \
|
||||
runtime/tutor/tutor1.??_??.utf-8 \
|
||||
runtime/tutor/tutor1.bar \
|
||||
runtime/tutor/tutor1.bar.utf-8 \
|
||||
runtime/tutor/tutor2.utf-8 \
|
||||
runtime/tutor/tutor2.?? \
|
||||
runtime/tutor/tutor2.??.utf-8 \
|
||||
runtime/spell/README.txt \
|
||||
|
@ -1,5 +1,7 @@
|
||||
# Welcome to the VIM Tutor
|
||||
|
||||
# CHAPTER ONE
|
||||
|
||||
Vim is a very powerful editor that has many commands, too many to explain in
|
||||
a tutor such as this. This tutor is designed to describe enough of the
|
||||
commands that you will be able to easily use Vim as an all-purpose editor.
|
||||
@ -38,7 +40,7 @@ instead of text to type.
|
||||
|
||||
Now, move to the next lesson (use the `j`{normal} key to scroll down).
|
||||
|
||||
## Lesson 1.1: MOVING THE CURSOR
|
||||
# Lesson 1.1: MOVING THE CURSOR
|
||||
|
||||
** To move the cursor, press the `h`, `j`, `k`, `l` keys as indicated. **
|
||||
|
||||
@ -87,7 +89,7 @@ NOTE: [:q!](:q) <Enter> discards any changes you made. In a few lessons you
|
||||
|
||||
5. Move the cursor down to Lesson 1.3.
|
||||
|
||||
## Lesson 1.3: TEXT EDITING - DELETION
|
||||
# Lesson 1.3: TEXT EDITING - DELETION
|
||||
|
||||
** Press `x`{normal} to delete the character under the cursor. **
|
||||
|
||||
@ -430,7 +432,7 @@ Notice that [c](c)e deletes the word and places you in Insert mode.
|
||||
5. Type `c$`{normal} and type the rest of the line like the second and press `<Esc>`{normal}.
|
||||
|
||||
The end of this line needs some help to make it like the second.
|
||||
The end of this line needs to be corrected using the `c$`{normal} command.
|
||||
The end of this line needs to be corrected using the c$ command.
|
||||
|
||||
NOTE: You can use the Backspace key to correct mistakes while typing.
|
||||
|
||||
@ -907,8 +909,8 @@ Vim has many more features than Vi, but most of them are disabled by
|
||||
default. To start using more features you have to create a "vimrc" file.
|
||||
|
||||
1. Start editing the "vimrc" file. This depends on your system:
|
||||
for UNIX-like for Windows
|
||||
`:e ~/.vimrc`{vim} `:e ~/_vimrc`{vim}
|
||||
for UNIX-like for Windows
|
||||
`:e ~/.vimrc`{vim} `:e ~/_vimrc`{vim}
|
||||
|
||||
2. Now read the example "vimrc" file contents:
|
||||
`:r $VIMRUNTIME/vimrc_example.vim`{vim}
|
||||
@ -958,6 +960,9 @@ NOTE: Completion works for many commands. It is especially useful for
|
||||
|
||||
# CONCLUSION
|
||||
|
||||
This concludes Chapter 1 of the Vim Tutor. Consider continuing with
|
||||
[Chapter 2](@tutor:tutor:vim-02-beginner).
|
||||
|
||||
This was intended to give a brief overview of the Vim editor, just enough to
|
||||
allow you to use the editor fairly easily. It is far from complete as Vim has
|
||||
many many more commands. Consult the help often.
|
||||
|
@ -1,45 +1,45 @@
|
||||
{
|
||||
"expect": {
|
||||
"24": -1,
|
||||
"103": "The cow jumped over the moon.",
|
||||
"124": "There is some text missing from this line.",
|
||||
"125": "There is some text missing from this line.",
|
||||
"144": "There is some text missing from this line.",
|
||||
"145": "There is some text missing from this line.",
|
||||
"146": "There is also some text missing here.",
|
||||
"147": "There is also some text missing here.",
|
||||
"220": "There are some words that don't belong in this sentence.",
|
||||
"236": "Somebody typed the end of this line twice.",
|
||||
"276": -1,
|
||||
"295": "This line of words is cleaned up.",
|
||||
"309": -1,
|
||||
"310": -1,
|
||||
"26": -1,
|
||||
"105": "The cow jumped over the moon.",
|
||||
"126": "There is some text missing from this line.",
|
||||
"127": "There is some text missing from this line.",
|
||||
"146": "There is some text missing from this line.",
|
||||
"147": "There is some text missing from this line.",
|
||||
"148": "There is also some text missing here.",
|
||||
"149": "There is also some text missing here.",
|
||||
"222": "There are some words that don't belong in this sentence.",
|
||||
"238": "Somebody typed the end of this line twice.",
|
||||
"278": -1,
|
||||
"297": "This line of words is cleaned up.",
|
||||
"311": -1,
|
||||
"312": -1,
|
||||
"313": -1,
|
||||
"314": -1,
|
||||
"315": -1,
|
||||
"332": "Fix the errors on this line and replace them with undo.",
|
||||
"372": -1,
|
||||
"373": -1,
|
||||
"316": -1,
|
||||
"317": -1,
|
||||
"334": "Fix the errors on this line and replace them with undo.",
|
||||
"374": -1,
|
||||
"375": -1,
|
||||
"389": "When this line was typed in, someone pressed some wrong keys!",
|
||||
"390": "When this line was typed in, someone pressed some wrong keys!",
|
||||
"411": "This line has a few words that need changing using the change operator.",
|
||||
"412": "This line has a few words that need changing using the change operator.",
|
||||
"432": "The end of this line needs to be corrected using the `c$` command.",
|
||||
"433": "The end of this line needs to be corrected using the `c$` command.",
|
||||
"497": -1,
|
||||
"516": -1,
|
||||
"541": "Usually the best time to see the flowers is in the spring.",
|
||||
"735": -1,
|
||||
"740": -1,
|
||||
"759": "This line will allow you to practice appending text to a line.",
|
||||
"760": "This line will allow you to practice appending text to a line.",
|
||||
"780": "Adding 123 to 456 gives you 579.",
|
||||
"781": "Adding 123 to 456 gives you 579.",
|
||||
"807": "a) This is the first item.",
|
||||
"808": "b) This is the second item."
|
||||
"376": -1,
|
||||
"377": -1,
|
||||
"391": "When this line was typed in, someone pressed some wrong keys!",
|
||||
"392": "When this line was typed in, someone pressed some wrong keys!",
|
||||
"413": "This line has a few words that need changing using the change operator.",
|
||||
"414": "This line has a few words that need changing using the change operator.",
|
||||
"434": "The end of this line needs to be corrected using the c$ command.",
|
||||
"435": "The end of this line needs to be corrected using the c$ command.",
|
||||
"499": -1,
|
||||
"518": -1,
|
||||
"543": "Usually the best time to see the flowers is in the spring.",
|
||||
"737": -1,
|
||||
"742": -1,
|
||||
"761": "This line will allow you to practice appending text to a line.",
|
||||
"762": "This line will allow you to practice appending text to a line.",
|
||||
"782": "Adding 123 to 456 gives you 579.",
|
||||
"783": "Adding 123 to 456 gives you 579.",
|
||||
"809": "a) This is the first item.",
|
||||
"810": "b) This is the second item."
|
||||
}
|
||||
}
|
||||
|
194
runtime/tutor/en/vim-02-beginner.tutor
Normal file
194
runtime/tutor/en/vim-02-beginner.tutor
Normal file
@ -0,0 +1,194 @@
|
||||
# Welcome to the VIM Tutor
|
||||
|
||||
# CHAPTER TWO
|
||||
|
||||
Hic Sunt Dracones: if this is your first exposure to vim and you
|
||||
intended to avail yourself of the introductory chapter, kindly type
|
||||
on the command line of the Vim editor
|
||||
~~~ cmd
|
||||
:Tutor vim-01-beginner
|
||||
~~~
|
||||
Or just open the [first chapter](@tutor:vim-01-beginner) of the tutor at the link.
|
||||
|
||||
The approximate time required to complete this chapter is 8-10 minutes,
|
||||
depending upon how much time is spent with experimentation.
|
||||
|
||||
|
||||
# Lesson 2.1.1: THE NAMED REGISTERS
|
||||
|
||||
** Store two yanked words concurrently and then paste them **
|
||||
|
||||
1. Move the cursor to the line below marked ✓
|
||||
|
||||
2. Navigate to any point on the word 'Edward' and type `"ayiw`{normal}
|
||||
|
||||
**MNEMONIC**: *into register(") named (a) (y)ank (i)nner (w)ord*
|
||||
|
||||
3. Navigate forward to the word 'cookie' (`fk`{normal} or `2fc`{normal}
|
||||
or `$2b`{normal} or `/co`{normal} `<ENTER>`{normal}) and type `"byiw`{normal}
|
||||
|
||||
4. Navigate to any point on the word 'Vince' and type `ciw<CTRL-r>a<ESC>`{normal}
|
||||
|
||||
**MNEMONIC**: *(c)hange (i)nner (w)ord with <contents of (r)egister> named (a)*
|
||||
|
||||
5. Navigate to any point on the word 'cake' and type `ciw<CTRL-r>b<ESC>`{normal}
|
||||
|
||||
a) Edward will henceforth be in charge of the cookie rations
|
||||
b) In this capacity, Vince will have sole cake discretionary powers
|
||||
|
||||
NOTE: Delete also works into registers, i.e. `"sdiw`{normal} will delete
|
||||
the word under the cursor into register s.
|
||||
|
||||
REFERENCE: [Registers](registers)
|
||||
[Named Registers](quotea)
|
||||
[Motion](text-objects)
|
||||
[CTRL-R](i_CTRL-R)
|
||||
|
||||
|
||||
# Lesson 2.1.2: THE EXPRESSION REGISTER
|
||||
|
||||
** Insert the results of calculations on the fly **
|
||||
|
||||
1. Move the cursor to the line below marked ✗
|
||||
|
||||
2. Navigate to any point on the supplied number
|
||||
|
||||
3. Type `ciw<CTRL-r>=`{normal}60\*60\*24 `<ENTER>`{normal}
|
||||
|
||||
4. On the next line, enter insert mode and add today's date with
|
||||
`<CTRL-r>=`{normal}`system('date')`{vim} `<ENTER>`{normal}
|
||||
|
||||
NOTE: All calls to system are OS dependent, e.g. on Windows use
|
||||
`system('date /t')`{vim} or `:r!date /t`{vim}
|
||||
|
||||
I have forgotten the exact number of seconds in a day, is it 84600?
|
||||
Today's date is:
|
||||
|
||||
NOTE: the same can be achieved with `:pu=`{normal}`system('date')`{vim}
|
||||
or, with fewer keystrokes `:r!date`{vim}
|
||||
|
||||
REFERENCE: [Expression Register](quote=)
|
||||
|
||||
|
||||
# Lesson 2.1.3: THE NUMBERED REGISTERS
|
||||
|
||||
** Press `yy`{normal} and `dd`{normal} to witness their effect on the registers **
|
||||
|
||||
1. Move the cursor to the line below marked ✓
|
||||
|
||||
2. yank the zeroth line, then inspect registers with `:reg`{vim} `<ENTER>`{normal}
|
||||
|
||||
3. delete line 0. with `"cdd`{normal}, then inspect registers
|
||||
(Where do you expect line 0 to be?)
|
||||
|
||||
4. continue deleting each successive line, inspecting `:reg`{vim} as you go
|
||||
|
||||
NOTE: You should notice that old full-line deletions move down the list
|
||||
as new full-line deletions are added
|
||||
|
||||
5. Now (p)aste the following registers in order; c, 7, 4, 8, 2. i.e. `"7p`{normal}
|
||||
|
||||
0. This
|
||||
9. wobble
|
||||
8. secret
|
||||
7. is
|
||||
6. on
|
||||
5. axis
|
||||
4. a
|
||||
3. war
|
||||
2. message
|
||||
1. tribute
|
||||
|
||||
|
||||
NOTE: Whole line deletions (`dd`{normal}) are much longer lived in the
|
||||
numbered registers than whole line yanks, or deletions involving
|
||||
smaller movements
|
||||
|
||||
REFERENCE: [Numbered Registers](quote0)
|
||||
|
||||
|
||||
# Lesson 2.1.4: THE BEAUTY OF MARKS
|
||||
|
||||
** Code monkey arithmetic avoidance **
|
||||
|
||||
NOTE: a common conundrum when coding is moving around large chunks of code.
|
||||
The following technique helps avoid number line calculations associated
|
||||
with operations like `"a147d`{normal} or `:945,1091d a`{vim} or even worse
|
||||
using `i<CTRL-r>=`{normal}1091-945 `<ENTER>`{normal} first
|
||||
|
||||
1. Move the cursor to the line below marked ✓
|
||||
|
||||
2. Go to the first line of the function and mark it with `ma`{normal}
|
||||
|
||||
NOTE: exact position on line is NOT important!
|
||||
|
||||
3. Navigate to the end of the line and then the end of the code block
|
||||
with `$%`{normal}
|
||||
|
||||
4. Delete the block into register a with `"ad'a`{normal}
|
||||
|
||||
**MNEMONIC**: *into register(") named (a) put the (d)eletion from the cursor to
|
||||
the LINE containing mark(') (a)*
|
||||
|
||||
5. Paste the block between BBB and CCC `"ap`{normal}
|
||||
|
||||
NOTE: practice this operation multiple times to become fluent `ma$%"ad'a`{normal}
|
||||
|
||||
~~~ cmd
|
||||
AAA
|
||||
function itGotRealBigRealFast() {
|
||||
if ( somethingIsTrue ) {
|
||||
doIt()
|
||||
}
|
||||
// the taxonomy of our function has changed and it
|
||||
// no longer makes alphabetical sense in its current position
|
||||
|
||||
// imagine hundreds of lines of code
|
||||
|
||||
// naively you could navigate to the start and end and record or
|
||||
// remember each line number
|
||||
}
|
||||
BBB
|
||||
CCC
|
||||
~~~
|
||||
|
||||
NOTE: marks and registers do not share a namespace, therefore register a is
|
||||
completely independent of mark a. This is not true of registers and
|
||||
macros.
|
||||
|
||||
REFERENCE: [Marks](marks)
|
||||
[Mark Motions](mark-motions) (difference between ' and \`)
|
||||
|
||||
|
||||
# Lesson 2.1 SUMMARY
|
||||
|
||||
1. To store (yank, delete) text into, and retrieve (paste) from, a total of
|
||||
26 registers (a-z)
|
||||
2. Yank a whole word from anywhere within a word: `yiw`{normal}
|
||||
3. Change a whole word from anywhere within a word: `ciw`{normal}
|
||||
4. Insert text directly from registers in insert mode: `<CTRL-r>a`{normal}
|
||||
|
||||
5. Insert the results of simple arithmetic operations:
|
||||
`<CTRL-r>=`{normal}60\*60 `<ENTER>`{normal} in insert mode
|
||||
6. Insert the results of system calls:
|
||||
`<CTRL-r>=`{normal}`system('ls -1')`{vim} in insert mode
|
||||
|
||||
7. Inspect registers with `:reg`{vim}
|
||||
8. Learn the final destination of whole line deletions: `dd`{normal} in
|
||||
the numbered registers, i.e. descending from register 1 - 9. Appreciate
|
||||
that whole line deletions are preserved in the numbered registers longer
|
||||
than any other operation
|
||||
9. Learn the final destination of all yanks in the numbered registers and
|
||||
how ephemeral they are
|
||||
|
||||
10. Place marks from command mode `m[a-zA-Z0-9]`{normal}
|
||||
11. Move line-wise to a mark with `'`{normal}
|
||||
|
||||
|
||||
# CONCLUSION
|
||||
|
||||
This concludes chapter two of the Vim Tutor. It is a work in progress.
|
||||
|
||||
This chapter was written by Paul D. Parker.
|
||||
|
||||
Modified for vim-tutor-mode by Restorer.
|
10
runtime/tutor/en/vim-02-beginner.tutor.json
Normal file
10
runtime/tutor/en/vim-02-beginner.tutor.json
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
"expect": {
|
||||
"36": -1,
|
||||
"37": "b) In this capacity, Edward will have sole cookie discretionary powers",
|
||||
"64": "I have forgotten the exact number of seconds in a day, is it 86400",
|
||||
"65": -1,
|
||||
"91": -1,
|
||||
"138": -1
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user