Editors (Vim) #
Lecture source: https://missing.csail.mit.edu/2020/editors/
Movements, edits, counts, modifiers.
Exercises #
-
(Advanced) Convert XML to JSON (example file) using Vim macros. Try to do this on your own, but you can look at the macros section above if you get stuck.
-
Gdd,ggdddelete first and last lines -
Macro to format a single element (register
e)- Go to line with
<name> qe^r"f>s": "<ESC>f<C"<ESC>qqe: start recording a macro in registere.^: go to first non-blank character (that is<).r": replace it as".f>: find forward>on the current line.s": "<ESC>: substitute the>, replace it as": ", then leave the insert mode.f<: find forward<on the current line.C"<ESC>: delete from cursor to the end of the line, add"at the end, then leave the insert mode.q: stop recording macro.
- Go to line with
-
Macro to format a person (register
p)- Go to line with
<person> qpS{<ESC>j@eA,<ESC>j@ejS},<ESC>qqp: start recording a macro in registerp.S{<ESC>: delete line and insert{, then leave the insert mode.j: move one line down.@e: replays theemacro (for name property).A,<ESC>:j: move one line down.@e: replays theemacro (for email property).j: move one line down.S},<ESC>: delete line and insert},, then leave the insert mode.q: stop recording macro.
- Go to line with
-
Macro to format a person and go to the next person (register
q)- Go to line with
<person> qq@pjqqq: start recording a macro in registerq.@p: replays thepmacro (to format a person).j: move one line down.q: stop recording macro.
- Go to line with
-
Execute macro until end of file
999@q
-
Manually remove last
,and add[and]delimiters
-