I'm trying this exercise from The missing semester of your CS Education, Lecture 3: Editors (Vim):
They give this solution:
Gdd, ggdd
delete first and last linese
)
<name>
qe^r"f>s": "<ESC>f<C"<ESC>q
p
)
<person>
qpS{<ESC>j@eA,<ESC>j@ejS},<ESC>q
q
)
<person>
qq@pjq
999@q
,
and add [
and ]
delimitersI don't understand commands like:
<C
^r"f>s":
S{<ESC>j@eA,<ESC>j@ejS}
Among others, could someone do a breakdown of the solution in order to understand the commands?
<C
This one is meaningless because you split the command at the wrong place. The correct place is between f<
and C"
:
f<
means "move the cursor to the next <
on the line", see :help f
.C"
means "cut the rest of the line and insert a "
", see :help C
.^r"f>s":
^
means "move the cursor to the first printable character of the line", see :help ^
.r"
means "replace the current character with a "
", see :help r
.f>
means "move the cursor to the next >
on the fine", see :help f
.s":
is actually s": "
, meaning "replace the current character with ": "
, see :help s
.S{<ESC>j@eA,<ESC>j@ejS}
S{
means "replace the whole line with a "
at the correct indentation", see :help S
.<ESC>
is the Escape
key, see :help key-notation
.j
means "go down one line", see :help j
.@e
means "play back macro stored in register e
", see :help @
.A,
means "append a ,
at the end of the line", see :help A
.<ESC>
, j
, @e
, j
, and S}
have already been explained.All of that is pretty easy to piece out after a while (I rarely need to use Vim itself when answering Vim questions) but it sure is a lot to take in without the proper foundations.
That cryptic example is really a case of giving the reader a quasi-magical fish instead of teaching them how to fish. I am not sure what the people behind those "get rich quick" Vim articles and courses think they are achieving but questions like this one should make them pause a little.
The subject matter is much too complex to be covered in one lecture or in a short webpage so I would suggest you learn Vim properly instead of consuming context-free content like this.
$ vimtutor
as many times as needed to get the basics right.:help user-manual
. It's a hands-on tutorial that will guide you progressively through every feature, from basic to advanced. Go at your own pace and, most importantly, experiment along the way.