Created
February 17, 2017 16:37
-
-
Save schas002/8870d5af1161f0cf05016175328c9206 to your computer and use it in GitHub Desktop.
Yet another Vim tutorial, part 1: basic editing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##### ===== ----- > Yet another Vim tutorial, Part 1 < ----- ===== ##### | |
# Vim is an ubiquitous text editor built to make creating and changing # | |
# any kind of text very efficient. (http://www.vim.org/) # | |
# This is yet another Vim tutorial. # | |
# The first part is about basic editing. # | |
If you see some text like | |
/-\ | |
|!|-|int! | |
\-/ | |
then there is a hint! :D | |
If you see some text like `Exercise:`, then that's an exercise that you | |
might want to train on. | |
Now, ensure that Caps Lock is not on, and press `j` some times so that | |
the start of the Basics section fits fully on the screen. Or `Down`, | |
whatever your heart feels. | |
///// Basics /////////////////////////////////////////////////////////// | |
h, j, k and l are Vim cursor keys! | |
k Hints: h is on the left and moves to the left | |
h --+-- l l is the opposite - on the right and moves to the right | |
j k has an ascender which points up | |
j is the opposite - has a descender which points down | |
I'll wait below until you're comfortable with the cursor keys. | |
/-\ The regular cursor keys (the arrow keys) work, too. But you | |
|!|-|int! should use the Vim cursor keys as they are much closer to the | |
\-/ hands than regular cursor keys! | |
||||| Insert mode |||||||||||||||||||||||||||||||||||||||||||||||||||||| | |
Press `i` to enter insert mode. Once you enter insert mode, the words | |
`-- INSERT --` should appear on the status-bar below, and you can type | |
in text. Press `Ctrl-C` or `Escape` to exit to normal mode. | |
/-\ Insert mode is actually very similar to a GUI text editor! | |
|!|-|int! You can use cursor/navigation keys, backspace, delete and | |
\-/ more! | |
Exercise: This text makes absolutely no sense. Fix it by using the | |
insert mode. | |
I have a that my four little will one day in a nation where they will | |
not be by the of their skin but by the of their character. | |
-- Martin Luther King, Jr. -- "I Have a Dream" -- 1963 | |
(wq: http://linkr.xyz/r/Bk-sBK4tl) | |
(source wp: https://en.wikipedia.org/wiki/I_Have_a_Dream) | |
||||| Deletion ||||||||||||||||||||||||||||||||||||||||||||||||||||||||| | |
Press `x` to delete the current character. Press `X` to delete the | |
character to the left. | |
Exercise: That one guy was *so* dumb, he even typed random characters! | |
That's just dumb! Fix the text using the deletion keys! | |
IIt iss amazzinng www.hat you ccan accommpplish iff you ddto nott | |
carree www.ho gettys thhe creddit. | |
-- Harry S. Truman (?) | |
(wq: https://en.wikiquote.org/wiki/Harry_S._Truman#Misattributed) | |
||||| Append mode |||||||||||||||||||||||||||||||||||||||||||||||||||||| | |
Press `A` to enter append mode. It is insertion mode, but the text gets | |
inserted at the end of the line (wherever you are in the line!). | |
Exercise: That one guy was *so* dumb, he even hit me while I was | |
writing! That's just dumb! Fix the text using the append | |
mode! | |
Most people would rather die than think; in f | |
-- Bertrand Russell -- "The ABC of Relativity" -- 1925 | |
(wq: https://en.wikiquote.org/wiki/Bertrand_Russell#1920s) | |
|| Lesson Paused | |
h, j, k and l are Vim cursor keys -- use them as they are much closer | |
to the hands than regular cursor keys! | |
`i` enters insert mode! | |
`x` deletes a character, `X` back-spaces a character! | |
`A` appends text at end of line! | |
But wait, don't tune out! There's an exercise of your skills before we | |
continue to the Electives, and that's where things become more fun! :D | |
|> Unpause | |
Exercise: Use the skills gained to fix the text! | |
Exxxperieencce thhe nname givves tto mi | |
-- Oscar Wilde -- Lady Windermere's Fan -- 1892 | |
(wq: http://linkr.xyz/r/SyzAnY4Ke) | |
(source wp: https://en.wikipedia.org/wiki/Lady_Windermere%27s_Fan) | |
But wait, don't switch channels! Now we will begin the Electives, and | |
that's where things become more fun! :D | |
\\\\\ Electives \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ | |
Press `u` to undo the last action. Press `C-R` to redo the last undone | |
action. | |
/-\ Vim gives short names to modifier key combinations. `C-R`, in | |
|!|-|int! this case, means `Ctrl-R`! | |
\-/ | |
I hope you don't undo your exercises so far. | |
----- Jumps ------------------------------------------------------------ | |
Press `0` to jump to the beginning of the line, `$` to jump to the end | |
of the line. `^` jumps to the first non-white-space character in the | |
line. | |
___ ___ | |
0 _.-' '-._ ^ _.-' '-._ $ | |
|_.-' '-._|_.-' '-._| | |
This is a line!1!!11! | |
----- "words" ---------------------------------------------------------- | |
Use `w`, `b` and `e` to move along "words". A "word" is a sequence of | |
characters either of the alphanumeric or special characters type. | |
.- cursor somewhere here | |
b|e w | |
|v| | | |
alg HelloWorld | |
----- "WORDS!" --------------------------------------------------------- | |
Use `W`, `B` and `E` to move along "WORDS!" A "WORD!" is a sequence of | |
any characters that are not whitespace! | |
/-\ Remember: "words" are not "WORDS!" They differ in what | |
|!|-|int! characters are captured! | |
\-/ | |
.- cursor somewhere here | |
b | e w | |
| v | | | |
beg int thing, thingything, thingamabobajig | |
----- Replace mode ----------------------------------------------------- | |
Press `R` to enter replace mode. It is insertion mode, but the text | |
gets replaced over existing characters. | |
Exercise: Fill in the blanks with replace mode! :D | |
All _______ are _____ - but some _______ are more _____ than others. | |
-- Animal Farm by George Orwell -- Chapter 10 -- 1945 | |
(wq: https://en.wikiquote.org/wiki/Animal_Farm#Chapter_10) | |
(source wp: https://en.wikipedia.org/wiki/Animal_Farm) | |
----- Extended commands ------------------------------------------------ | |
The last thing in each lesson is learning some extended commands. | |
Press `:` to start an extended command. Next, type the extended | |
command, and press `Enter` to send the extended command. | |
Today, we will learn some crucial commands. | |
::::: :w - write ::::::::::::::::::: | |
: -------------------------------- : | |
: | Synopsis: | :w | :w FILENAME | : | |
: -------------------------------- ::::::::::::::::::::::::::::::::::::: | |
: Write the current file in the buffer into FILENAME. If FILENAME is : | |
: omitted, write the current file in the buffer into the current file. : | |
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
::::: :q - quit :::::::::::: | |
: ------------------------ : | |
: | Synopsis: | :q | :q! | : | |
: ------------------------ ::::::::::::::::::::::::::::::::::::::::::::: | |
: Quit Vim. If ! is omitted, and there are changes, the command will : | |
: fail. If the current tile is not the only tile currently open : | |
: (tutorial coming soon), the command will close the current tile : | |
: instead. : | |
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
::::: :wq - write and quit ::::::::::: | |
: ---------------------------------- : | |
: | Synopsis: | :wq | :wq FILENAME | : | |
: ---------------------------------- ::::::::::::::::::::::::::::::::::: | |
: Write the current file in the buffer into FILENAME and quit Vim. If : | |
: FILENAME is omitted, write the current file in the buffer into the : | |
: current file. If the current tile is not the only tile currently : | |
: open (tutorial coming soon), the command will, after writing, close : | |
: the current tile instead. : | |
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: | |
Exercise: save the current file into *another file* by typing | |
`:w FILENAME`, replacing FILENAME with the filename that will | |
work best. I suggest `yavt-part1-YOUR-NAME.txt`, where | |
YOUR-NAME is, well, your name! | |
But don't think about `:q`ing yet! There's a final exercise! | |
|| Lesson Paused | |
`u` undoes the last action, `C-R` redoes the last undo! | |
`0` jumps to the "hard" beginning of line, `$` to the end of line, `^` | |
to the "soft" beginning of line! | |
Use `w`, `b` and `e` to move along "words"! | |
Use `W`, `B` and `E` to move along "WORDS!" | |
`R` enters replace mode! | |
::::: Extended commands ::::: | |
: ----------------- : | |
: | :w | :q | :wq | : | |
: ----------------- : | |
::::::::::::::::::::::::::::: | |
But don't think about `:q`ing yet! There's the final exercise! | |
|> Unpause | |
Exercise: Use the skills you learned so far to fix the text! :D | |
To-morrow, and _________, annd _________, creepps in this peetty pace | |
from daay, to thhe last of reeccordeed _____; and all our have | |
liightted the to duusty ______. Out, ____, brieeff | |
-- Macbeth by William Shakespeare - Act V - c. 1605 | |
(wq: https://en.wikiquote.org/wiki/Macbeth#Act_V) | |
(source wp: https://en.wikipedia.org/wiki/Macbeth) | |
Once you finished the final exercise, you can get a pat on your back, | |
for | |
---------------------------------------------------- | |
| You Finished Yet Another Vim Tutorial, Part One! | | |
---------------------------------------------------- | |
<> Eject | |
Now, you can `:wq` safely, with your shiny new skills! | |
# This work by Andrew Zyabin (@schas002) is licensed under a Creative # | |
# Commons Attribution-ShareAlike 3.0 Unported license. # | |
# The license is available at # | |
# https://creativecommons.org/licenses/by-sa/3.0/. # | |
##### ===== ----- > End of yet another Vim tutorial! < ----- ===== ##### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment