Is there a map I can do that will move the anchor with the cursor so the selection stays the same size?
The problem I’m trying to solve in case there are alternate solutions. I do a bit of diagramming and sometimes I need to move a bit of the diagram around to a new line and position. Example:
A.Offset
| B.Offset
| | A.Length
| | | B.Length
V V V V
|------|------|------|------|------|------|------|------|------|
0 5 10 15 20 25 30 35 40 45
Now say I want to copy this diagram and update it so that B moves to the right 10 units. First I use C to select both B.Length and it’s V arrow and move them over 10 units by adding spaces.
A.Offset
| B.Offset
| | A.Length
| | | ..............B.Length
V V V ..............V
|------|------|------|------|------|------|------|------|------|
0 5 10 15 20 25 30 35 40 45
Now I want to move B.Offset to the right of and below A.Length. What I’d like to do is select B.Offset and d yank and delete it, then move the whole selection (anchor and cursor) down two lines and to the right 14 columns so that it overlays the new spaces I just inserted. Then I can R replace the spaces with the yank.
A.Offset
|
| | A.Length
| | | B.Offset......B.Length
V V V ..............V
|------|------|------|------|------|------|------|------|------|
0 5 10 15 20 25 30 35 40 45
Not moving the anchor means that I have to mentally keep track of how big the selection was and manually select that many spaces for R replacement. Or p paste the yank and then d delete the spaces until B.Length is re-aligned with the V arrow again.
It’s not the worst kind of reply, it’s actually a very valid point. I have used ASCIIFlow before, but I would like something that isn’t a webpage and also outputs ascii/unicode. I do most of my work in a terminal, so I’d like to stay there as much a possible. I’m actually writing a little terminal program to do art primitives, but it not ready for prime time yet.
and same with L. I’m not sure it works as well with j and k but I didn’t need it.
For your use case though, what I’d do is probably use a combination of
the & key which allows to align selections by adding spaces
C or <a-C> to Copy selection from one line to another, keeping alignement and size
Step by step :
/25<ret>Z
To quickly go to the pipe you want to align to and mark the selection kk<a-C>
To select the beginning of V and B.length <a-z>a&
To append back the 25 pipe to the selection and align the selections, inserting spaces uUr.
Undo redo to select what’s just been added and replace it with points /B\.O<ret>Ed
To select B.Offset and yankdelete it (\.)\.
Or anything that gets you back to the beginning of …B.Length
Then you have a lot of options :
simply insert B.Offset, delete the dot and realign B.length with V using the & and uUr tricks. It is the most particular and hardest to turn into a mapping solution, but it may be fast enough that we don’t even need a mapping, especially if we think of aligning B.Length, V and 25 last rather than first.
Use an intermediate line to put work with what you copy, & and C
Shell out to get the length of the yank register (${#varl} or something, idk), and craft a selection accordingly, that you can then R replace.
plenty of other ways probably
Because I like solution 2 the most, here is my jab at it (remember, the cursor is at the beginning of what we want to replace) : \<a-o>
to insert a new line without hook, so as to not trigger automatic indentation ZjP<a-z>a
to save the selection, go to the empty line and paste what we want to insert, selecting it and append back our previous selection <a-:><a-;>&
To align. We have to ensure the cursor is at the beginning of each selection, as & aligns cursors. ,
To keep only what we just pasted as selection <a-C>
to select the corresponding chunk on the line to make the insertion on (with undesired consequences if there is no room ! There is probably a more robust and much more lengthy solution than <a-C> using <a-z>u) <a-(>
to exchange the selections. ,x<a-d>
To clear the temporary line. <a-U>(,
to select what you just inserted.
I had a passing thought that it could be solved by mapping with the <a-;>, I just hadn’t taken the time to dig into it. The H<a-;>H<a-;> works really well. It seems the hard part is finding a good mapping for it. H K L all have an available <c-*> mapping available ( I don’t use the history navigation ). But <c-j> is eaten by legacy VT codes and <a-j> is too useful to remap.
Another way to do this is using selections_desc. It contains each cursor/anchor position in the format 1.2,3.4. So you can write a script that computes the length of each selection in a register, then add it to the current selections desc.
For example:
Press Z to save selections_desc to register caret
Go somewhere else
Find the lengths of each selection (1.2,3.4 => |2-4| = 2) and add it to the current selections_desc with :select