4 ms·
More fun with vim. Assume you have a vim editor open with multiple files, each of which need to have their lines lexicographically reversed. Is this a contriv
by AdieuToLogic 3y ago
More fun with vim.
Assume you have a vim editor open with multiple files, each of which need to have their lines lexicographically reversed. Is this a contrived example? Sure, but bear with me for a moment.
A macro can do this pretty easily and could be recorded via 'q<buffer>', where '<buffer>' is a letter. But recording macros this way can be a bit opaque. Plus, having to manually invoke it for each buffer is suboptimal.
Here is one way to do the above:
- enter the desired commands on an empty line (such as :1,$ !sort -r^M:w!^M)
- review the vim commands and refine as you see fit.
- execute the following in normal mode on the same line (to load the 'a' register): 0"ay$
- execute the following ex command (to discard loading the 'a' buffer): :e!
- execute the following ex command (to apply 'a' to all buffers): :bufdo normal @a
In this example, all buffers in the vim session will have the commands in the 'a' buffer applied (reverse sort their lines and contents saved).