Move anchor and cursor together

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.

Worst kind of reply incoming, fair warning.

Maybe a different tool would serve you better, like for ascii diagrams, ASCIIFlow

or, my personal favorite tool for doing diagrams in text is: https://d2lang.com/

… and now that I think about it, d2 have an ascii diagram output format would be cool.

… additially, sorry for no real help on your question :stuck_out_tongue:

1 Like

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.

D2 rocks and has a built in auto-formatter and is just done in text!

I am a bit of a D2 fanboy.

Hacked this together for sake of a challenge/practice:

define-command preview-replace %{
	remove-hooks window preview-replace

	hook -group preview-replace window RawKey <esc>|R %{
		remove-hooks window preview-replace
	}
	hook -group preview-replace window ModeChange '.*' %{
		remove-hooks window preview-replace
	}
	hook -group preview-replace window RawKey .* %{
		execute-keys ";%sh{echo ${#kak_reg_dquote}}<s-l><s-h><a-;>"
	}
}

Note that the selection will wrap over to the next line if the yanked text is too long.

1 Like

Cheers, I’ll give it a try.