This should be easy but it seems to be a blind spot in vim. I'm looking for a short one line mapping, let's say to <leader>r
, to right-align text inside a visual block selection. For example, consider the following sample text:
a1 a
b22 b
c234 c
d4444 d
After, in a visual block, selecting exactly the first '1' to the last '4' (a total of 16 characters) as so
a||||a
b|||| b
c|||| c
d|||| d
and executing our command we should get:
a 1a
b 22 b
c 234 c
d4444 d
If we could pipe the block selection to the UNIX utility rs
using rs -j 0 1
and replace the text in-place that would satisfy the problem. Presumably you should be able to delete (via d
), operate on the register, and paste (via p
), but I have not yet been able to get that to work.
Vim already has :right
which works linewise but no mechanism that seems to work on selections (for more on why I consider this a blind spot see :h *:visual_example*
). I have added the letters abcd
to break solutions which only work linewise instead of selection-wise and to break solutions which hinge on a common separator. The 234
string breaks trivial mirrors which aren't right-aligns in general. I have already reviewed the various table, align, and justify plugins and am not interested in them as an answer. If at all possible functions should be avoided.