Deep vi hacking when you have 400 files to edit with registers, macros, mksession and wv
Ok this is a truly deep post only for those who are living in vi/vim/neovim and have 400 files to manually edit (because they were idiots and didn't use shellcheck early enough for their many random bash scripts).
So if you have to do this, it rapidly becomes pretty old. You could try to write a really fancy awk script to fix things, but stuff like this does need a little bit of a manual touch still. So here are the tools that you need:
- Registers. There are 26 named registers where you can store things like say a
# shellcheck source=./include.shcommand that you have to write a million times. You specify the buffers with a double quote so
"iyymeans store into the register i, the entire line. and
"eYmeans put into register e everything from the cursor to the end of the line. To copy that register contents to wherever your cursor is, type
"ip to get register i. Note that the internet often confuses buffers for registers. In vi speak, buffers are where you stick files, where registers are where you stick little snippets.
- Macros. These are hard to find but kind of neat. This actually uses the same storage space as registers and really just stores, so to say start recording a macro into register q, you would start with
qagain. To execute the macro, use the ampersand like
@qand if you want to see what you've recorded,
"qwill put it at the cursor.
- Viewing macros and registers. One big problem is that there is no easy way to see what you have in your macros and registers, but there is a
:registerscommand to see it all, or just
:register abxif you want to see the contents of say the a, b and x registers.
Saving all this stuff
- Mksession. If you have a long running set of edits like this, then
:mksessionwill generate a
Session.vimfile in the current directory. So you can edit and edit and when you quit, do a
:mks!and when you restart run
vim -S. This saves all the buffers and open files.
- Viminfo. This is in
~/.viminfoand stores registers and macros but not what is in sessions. It is across multiple sessions, so serves as your overall session. If you want multiple of these, then you can run
wv Viminfoto stick it in the current directory and then you get restart both with
vi -S -i .Viminfo