-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathvimtutor-sequel.txt
799 lines (515 loc) · 26.3 KB
/
vimtutor-sequel.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
==============================================================================
= W e l c o m e t o t h e V I M T u t o r S e q u e l - Version 1.3 =
==============================================================================
Vimtutor Sequel is designed to continue your Vim education from
where the original vimtutor left off. It assumes you are familiar
with the basics of Vim and will cover more advanced topics and commands.
The approximate time required to complete the sequel is 30-60 minutes,
depending on how much time you spend experimenting.
ATTENTION:
The commands in the lessons will modify the text. Make a copy of this
file to practice on (if you started "vimtutor-sequel" this is already
a copy).
It is important to remember that this tutor is set up to teach by
use. That means that you need to execute the commands to learn them
properly. If you only read the text, you will forget the commands!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### TABLE OF CONTENTS ###
** To skip to a specific lesson, type: /Lesson [number] **
LESSONS:
Lesson 8: SPLITTING SCREENS
> 8.1: Creating Splits
> 8.2: Resizing Splits
Lesson 9: SPELLCHECK
Lesson 10: INDENTING, COMMENTING, AND CHANGING CASE
> 10.1: Indenting
> 10.2: Commenting
> 10.3: Changing Case
Lesson 11: ADVANCED SEARCH AND REPLACE
Lesson 12: MACROS
Lesson 13: VIM SCRIPTING
Lesson 14: VIM PLUGINS
Lesson 15: VIM SESSIONS AND REGISTERS
> 15.1: Vim Sessions
> 15.2: Vim Registers
Lesson 16: CHANGE NAVIGATION
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 8.1: CREATING SPLITS
Vim allows you to work on multiple files or different parts of the
same file simultaneously by splitting the screen. This feature greatly
enhances productivity when working on complex projects.
** To split the screen, use the following commands: **
:sp - split horizontally and open the same file in split screen
:vs - split vertically and open the same file in split screen
** To open a new file in a split, use: **
:sp [filename] - split horizontally and open [filename]
:vs [filename] - split vertically and open [filename]
1. Press :sp to create a horizontal split of this file.
2. Use CTRL-W j to move to the new split below.
3. Type :q to close the split and return to the original window.
4. Now use :vs to create a vertical split.
5. Press CTRL-W l to move to the new split on the right.
6. Again, use :q to close this split.
NOTE: CTRL-W followed by h, j, k, or l moves between splits.
7. Open a new file in a split by typing :sp hogwarts.txt
8. Type i to enter insert mode and write the following text:
"You're a wizard, Harry!" - Hagrid
9. Save the file with :w and close it with :q
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 8.2: RESIZING SPLITS
Once you've created splits, you might want to resize them to better
fit your needs.
** To resize splits, use the CTRL-W window command.**
CTRL-W + - increase height of current split
CTRL-W - - decrease height of current split
CTRL-W > - increase width of current split
CTRL-W < - decrease width of current split
CTRL-W = - make all splits equal size
1. Create a horizontal split with :sp
2. Press CTRL-W + several times to increase its height.
3. Now press CTRL-W - to decrease its height.
4. Create a vertical split with :vs
5. Use CTRL-W > to increase its width, and CTRL-W < to decrease it.
6. Use CTRL-W 4 > to increase its width 4 times.
7. Finally, press CTRL-W = to equalize all splits.
CHALLENGE: Create a layout with three splits:
- One large split on the left
- Two smaller splits stacked on the right
* Hint: you'll need to use :vs once and :sp once,
then resize the splits accordingly.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 8 SUMMARY
1. :sp and :vs split the screen horizontally and vertically.
2. CTRL-W h/j/k/l navigates between splits.
3. :q closes the current split.
4. You can open new or existing files in splits.
5. CTRL-W +/- changes the height of horizontal splits.
6. CTRL-W >/< changes the width of vertical splits.
7. CTRL-W = equalizes all splits.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 9: SPELLCHECK
Vim's built-in spellchecker can be a powerful tool for writing and
editing text.
** To enable spellcheck, first run this command: **
:setlocal spell spelllang=en_us - Enable spellcheck (US English)
You should now see misspelled words underlined in red.
** To use spellcheck, use the following commands: **
]s - Move to the next misspelled word
[s - Move to the previous misspelled word
z= - Suggest corrections for the word under the cursor
zg - Add the word under the cursor to the spell file
zw - Mark the word as incorrect
1. Enable spellcheck by typing :setlocal spell spelllang=en_us
2. Move through the following text using ]s and [s:
---> Ths is an exampel of a sentance with som mispeled words.
It was the beast of tims, it was the wurst of tims.
3. Place your cursor on a misspelled word above and press z= to see
suggestions and choose a correction by entering its number.
4. Try adding a correctly spelled but unrecognized word to the dictionary:
Place your cursor on "Vim" in the marked sentence below and press zg
---> I love Vim becuse Vim is powerfull. Vim users enjoy Vim.
5. Mark a correctly spelled word as incorrect:
Place your cursor on "the" below and press zw before adding it back to
the dictionary with zg.
---> The quick brown fox jumps over the lazy dog.
6. Finally, disable spellcheck with :set nospell
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 9 SUMMARY
1. :setlocal spell spelllang=en_us enables spellcheck.
2. ]s and [s navigate through misspelled words.
3. z= suggests corrections, zg adds words, zw marks words as incorrect.
4. :set nospell disables spellcheck.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 10.1 INDENTING
** To indent, comment, or change the case of multiple lines, use the
following commands. **
> - Indent the selected lines to the right
< - Indent the selected lines to the left
[count]> - Indent the selected lines by a certain number of levels
= - Auto-indent the selected lines (tries to guess the correct
indent)
To indent multiple lines at once, follow these steps:
1. Place your cursor on the first line of the Meditations quote below.
2. Press V} to select the paragraph.
3. Press > to indent the selected lines.
"Never let the future disturb you. You will meet it,
if you have to, with the same weapons of reason which
today arm you against the present."
4. To indent by a certain number of levels, use #> where # is the number.
Try indenting the following paragraph by three levels:
"The first rule of Fight Club is:
You do not talk about Fight Club.
The second rule of Fight Club is:
You do not talk about Fight Club."
5. Re-select the last visual selection with gv and unindent the paragraph.
CHALLENGE: Indent the following code properly using the = command:
int fibonacci(int n) {
if (n <= 1)
return n;
return fibonacci(n-1) + fibonacci(n-2);
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 10.2 COMMENTING
NOTE: Different programming languages use different comment symbols.
For demonstration, the examples below use the `#` symbol.
** For commenting/uncommenting a single line, use the following
commands: **
I# to comment out the line.
^x to uncomment the line.
** For multiple lines, use the following commands: **
:norm I# to comment out the selected lines.
:norm ^x to uncomment the selected lines.
1. Place your cursor on the first line of the Python code below.
2. Press V} to select the paragraph.
3. Type :norm I# to comment out the selected lines.
4. Now uncomment the paragraph by reselecting the block
and typing :norm ^x.
def greet(name):
print(f"Hello, {name}!")
print("Welcome to the world of Python.")
5. Re-select the last visual selection with gv and comment it out again.
6. To comment out a single line, use I# in normal mode:
print("Hello world!")
7. To uncomment a single line, use ^x in normal mode.
CHALLENGE: Comment out every other line in the following quote:
You don't even think to call me Godfather.
Instead, you come into my house on the day
my daughter is to be married, and you uh
ask me to do murder, for money.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 10.3 CHANGING CASE
** To change the case of text, use the following commands: **
guw - Convert to lowercase (word)
gUw - Convert to uppercase (word)
g~w - Toggle case (word)
gu} - Convert to lowercase (paragraph)
gU} - Convert to uppercase (paragraph)
1. Place your cursor at the start of each name and use gUw to
capitalize it:
harry potter
hermione granger
ron weasley
2. Now use gu} to convert this entire paragraph to lowercase:
HOGWART SCHOOL OF WITCHCRAFT AND WIZARDRY
HEADMASTER: ALBUS DUMBLEDORE
(ORDER OF MERLIN, FIRST CLASS, GRAND SORC., CHF. WARLOCK,
SUPREME MUGWUMP, INTERNATIONAL CONFED. OF WIZARDS)
3. Use g~w to toggle the case of each word in this spell:
wingardium leviosa
CHALLENGE: Using a combination of the case-changing commands, transform
the following text so that each house name is in uppercase, but
the rest of the text is in lowercase:
"Not Slytherin, eh?" said the small voice. "Are you sure? You could be
great, you know, it's all here in your head, and Slytherin will help you
on the way to greatness, no doubt about that - no? Well, if you're sure
- better be GRYFFINDOR!"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 10 SUMMARY
1. >, <, and = handle indentation.
2. I, ^x, :norm I#, and :norm ^x can be used to toggle comments for
one or multiple lines.
3. gu, gU, and g~ change the case of text.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 11: ADVANCED SEARCH AND REPLACE
Vim's search capabilities go beyond basic find operations.
** Advanced search commands: **
* - Search forward for the word under the cursor
# - Search backward for the word under the cursor
g* - Search forward for the partial word under the cursor
g# - Search backward for the partial word under the cursor
** For search and replace, use: **
:s/old/new/g - Replace occurences of 'old' with 'new' in the
current line
:s/old/new/gc - Replace with confirmation in the current line
:%s/old/new/g - Replace all occurrences of 'old' with 'new'
:%s/old/new/gc - Replace all occurrences with confirmation
1. Place your cursor on "vim" and press * to search forward for it:
vim editor vim vim editor vim
2. Now use # to search backward.
3. Place your cursor on "ed" and use g* to search for partial matches.
4. Replace "old" with "new" in the following text by selecting the line
in visual mode and typing :s/old/new/g
The old dog learned old tricks from an old book.
5. Now try with confirmation using :s/vim/emacs/gc. You can press y to
confirm, n to skip, a to replace all, and q to quit subsitutions.
I love vim because vim is powerful. Vim users enjoy vim. Vim is great.
CHALLENGE: Use advanced search and replace to change all instances of
"lion" to "penguin" and "Africa" to "Antarctica" in the
following paragraph. Use confirmation to decide which
instances to change:
My favorite animal is the lion. The lion
lives mostly in Africa. If you visit Africa,
you might see a lion.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 11 SUMMARY
1. * and # search for whole words, g* and g# for partial words.
2. :%s/old/new/g replaces all occurrences in the file.
3. Adding 'c' to the end prompts for confirmation on each replacement.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 12: MACROS
Macros allow you to record a sequence of commands and play them back.
** To use macros: **
qa - Start recording a macro into register 'a'
q - Stop recording
@a - Play back the macro stored in register 'a'
@@ - Repeat the last played macro
NOTE: We will discuss registers more in depth in Lesson 15.2. For
now, just know that registers are like named clipboards that can
store text or, in this case, a series of commands. You can use any
letter from a to z as a register name for your macros.
1. Place your cursor at the start of the first line below.
Type qa to start recording, then perform these actions:
- Change "TODO" to "DONE" using cw
- Move to the next line using j
- Type q to stop recording.
TODO: First task
TODO: Second task
TODO: Third task
2. Move back to the second line and type @a to play the macro.
3. Type @@ to repeat the macro for the third line.
CHALLENGE: Create a macro that will format the following ingredient list.
Each line should be capitalized and end with a period.
Example: "Russet potatoes: 3" becomes "Russet Potatoes: 3."
red onions: 2
butter stick: 4
yellow squash: 5
english cucumber: 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 12 SUMMARY
1. qa starts recording a macro into register 'a'.
2. q stops the recording.
3. @a plays back the macro, and @@ repeats the last macro.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 13: VIM SCRIPTING
Vim has its own scripting language that allows you to create
some functions and commands. This lesson will guide you through
creating, saving, and using Vim scripts.
** Basic Vim script syntax: **
let variablename = value " Assign a value to a variable
echo "message" " Print a message
function! FunctionName() " Define a function
endfunction " End function definition
call FunctionName() " Call a function
1. Let's create a simple function. First, open a new buffer by typing
`:new` followed by `Enter`. Then, enter insert mode and copy the
following function:
function! Lumos()
echo "Lumos Maxima! The tip of your wand lights up."
endfunction
After doing this, save the buffer as a script file by exiting
insert mode with `Esc` and then typing `:w myscript.vim` followed
by `Enter`.
2. Source the script file to load the function with the following:
:source myscript.vim
3. Now, let's call our function. In normal mode, type:
:call Lumos()
You should see "Lumos Maxima! The tip of your wand lights up."
4. Let's create a more complex function that uses a parameter:
Open `myscript.vim` if it's not already open (`:e myscript.vim`)
Insert the following function:
function! CastSpell(spell)
if a:spell == "Lumos"
echo "The tip of your wand lights up."
elseif a:spell == "Nox"
echo "The light at the tip of your wand goes out."
else
echo "You wave your wand, but nothing happens."
endif
endfunction
5. Once again, write and source the script file by using `:w` to
write the changes and `:source myscript.vim` to load the functions.
6. Now let's call our function with different spells:
:call CastSpell("Lumos")
:call CastSpell("Nox")
:call CastSpell("Expelliarmus")
7. We can also create custom commands. Insert the following in
`myscript.vim`:
command! Lumos call CastSpell("Lumos")
command! Nox call CastSpell("Nox")
Then write and source the updated commands.
Now you can use `:Lumos` and `:Nox` as commands!
8. Let's create a mapping. Let's map the Lumos spell to the leader key.
NOTE: The `<leader>` key is a special key used in Vim to create custom
shortcuts. By deafault, it is often set to the `\` key. However, you can
customize it in your `.vimrc`. For example, you can set it to `,` with:
let mapleader = ","
Type the following in `myscript.vim`:
nnoremap <leader>l :call CastSpell("Lumos")<CR>
Now, pressing <leader>l in normal mode will cast Lumos!
CHALLENGE: Create a function called "SortingHat" that takes a
name as a parameter and randomly assigns it to one
of the four Hogwarts houses. Then create a command
called :SortMe that calls this function with your
name.
Hint: You can use the random() function in Vim to generate a random
number.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 13 SUMMARY
1. `let` assigns a value to a variable.
2. `echo` prints a message.
3. `function!` and `endfunction` define a function.
4. `call` invokes a function.
5. Custom commands can be created using `command!`.
6. Mappings can be created with `nnoremap`.
7. The `<leader>` key is a special key that can be used to create custom
shortcuts and can be customized with `let mapleader = "your_key"`.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 14: VIM PLUGINS
Plugins extend Vim's functionality. Let's explore how to use them.
NOTE: For this lesson, we'll assume you're using vim-plug as your plugin
manager. If you haven't installed it yet, you can do so by following the
instructions at https://github.com/junegunn/vim-plug
** Basic vim-plug commands: **
:PlugInstall " Install plugins
:PlugUpdate " Update plugins
:PlugClean " Remove unused plugins
:PlugStatus " Check the status of plugins
1. To add a plugin, you need to modify your .vimrc file. Let's add the
'NERDTree' plugin, which provides a file system explorer. Add this
line to your .vimrc:
call plug#begin()
Plug 'preservim/nerdtree'
call plug#end()
2. Save your .vimrc and restart Vim. Then run :PlugInstall to install
the plugin.
3. Once installed, you can open NERDTree with :NERDTree
4. Let's add another useful plugin, 'vim-airline', which enhances the
status bar:
call plug#begin()
Plug 'preservim/nerdtree'
Plug 'vim-airline/vim-airline'
call plug#end()
5. Save, restart Vim, and run :PlugInstall again.
6. You should now see a more informative status bar at the bottom of
your Vim window.
CHALLENGE #1: Research and add a Vim plugin that adds Git integration to
Vim. Install it and try out its basic functionality.
CHALLENGE #2: Add the 'preservim/nerdcommenter' plugin to add robust
commenting functionality to Vim that overcome the
language-specific limitations of Vim's built-in "commenting".
Install it and try it out on a code file.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 14 SUMMARY
1. `:PlugInstall` installs plugins with `vim-plug`
2. `:PlugUpdate` updates plugins.
3. `:PlugClean` removes unused plugins.
4. `:PlugStatus` checks the status of plugins.
5. Plugins can be added to your `.vimrc` using `Plug 'plugin/repository'`.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 15.1: VIM SESSIONS
Vim sessions allow you to save your current work environment and restore
it later.
** Session commands: **
:mksession filename.vim " Create a session file
:source filename.vim " Load a session
:mksession! filename.vim " Update an existing session
1. Open a few files in split windows and create some modifications.
2. Now, let's save this session. Type:
:mksession test_session.vim
3. Quit Vim and restart this tutor with `vimtutor-sequel`.
4. To restore your session, type:
:source test_session.vim
5. Make some more changes, then update your session:
:mksession! test_session.vim
CHALLENGE: Create a complex window layout with at least three files open.
Save it as a session, quit Vim, then restore the session.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 15.2: VIM REGISTERS
Vim registers are like multiple clipboards that can store text and
commands.
** Register commands: **
"ay " Yank into register a
"ap " Paste from register a
:reg " View the contents of all registers
1. Yank the first line into register w by placing your cursor on it and
typing "wy$:
Wingardium Leviosa
2. Now move your cursor to the right of the arrow below and paste from
register w by typing "wp
--->
3. Copy the following line into register x:
Expelliarmus
4. View the contents of your registers by typing :reg
5. You can even use registers with macros. Record the following macro
into register m:
qmcwHogwarts<Esc>jq
6. Now apply this macro to the following lines using @m:
Beauxbatons
Durmstrang
Ilvermorny
CHALLENGE: Create a macro that swaps two words and store it in a register.
Apply this macro to swap the words in the following phrases:
- Potter Harry
- Weasley Ron
- Granger Hermione
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 15 SUMMARY
1. Vim sessions allow you to save and restore your working environment.
2. Use :mksession to create a session and :source to restore it.
3. Use " followed by a letter to specify a register for yanking or pasting.
4. The :reg command shows the contents of all registers.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 16: CHANGE NAVIGATION
This lesson covers commands that help you navigate through changes
and edits in your document efficiently.
** Useful change navigation commands: **
`. - Jump to position where the last change was made
g; - Go to position of last change
g, - Go to position of next change
gi - Go to the last place where you exited Insert mode
:earlier - Go to the state of the document at an earlier time
:later - Go to the state of the document at a later time
1. Make a change somewhere in this file, then move your cursor away.
Use `. to jump back to where you made the change.
2. Make several changes in different parts of this file. Then use g;
to move backwards through your change list, and g, to move forwards.
3. Navigate to the first arrow below and press `A` to append and type some
text. Press `Esc` and navigate to the second arrow. Now use `gi` to
return to where you last exited insert mode. Note how it resumes insert
mode.
--->
--->
4. Vim maintains a detailed history of changes, known as the undo tree.
This tree structure allows you to navigate to different states of your
document, even if those changes were made a while ago.
** Undo tree navigation examples: **
:earlier 5m - Go back 5 minutes in the document's history.
:later 5m - Move forward 5 minutes in the document's history.
:earlier 5f - Go back 5 changes in the file's history.
:later 5f - Move forward 5 changes in the file's history.
For more details, see `:help undo-tree`.
5. Replace the underscores with your name on the following line. Now,
use `:earlier 1f` to go back 1 change in your editing history.
Observe the change being reverted. Then, use `:later 1f` to move
forward 1 change.
---> My name is _____
CHALLENGE: Experiment with the `:earlier` and `:later` commands using
different time and change parameters. Notice how Vim allows you
to navigate through your document's state history efficiently.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Lesson 16 SUMMARY
1. `. jumps to the position where the last change was made.
2. g; and g, navigate through the change list.
3. gi returns to the last exited insert mode position.
4. :earlier and :later allow you to navigate through the document's
state history.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This concludes the Vimtutor Sequel. If you found this tutor helpful,
consider starring the repository on GitHub:
★ https://github.com/micahkepe/vimtutor-sequel
For contributing, reporting issues, or requesting new lessons, refer to
the CONTRIBUTING.md file in the repository.
For further learning, the following resources are recommended:
- Vim's built-in help system: :help
- Vim's official documentation: vimdoc.sourceforge.net
- Vim's user manual: Accessible with :help user-manual
Websites:
- Vimtricks.com
- Vimgenius.com
Books:
- Practical Vim - Drew Neil
- Learning the Vi and Vim Editors - Arnold Robbins
Remember, becoming a Vim wizard takes practice, so keep exploring
and experimenting with these features and more!
Written by Micah Kepe, 2024.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~