# Move anchor and cursor together

**URL:** <https://discuss.kakoune.com/t/move-anchor-and-cursor-together/2386>\
**Category:** Recipes & Guides\
**Created:** [January 25, 2024, 4:07pm UTC](https://discuss.kakoune.com/t/move-anchor-and-cursor-together/2386 "2024-01-25T16:07:19Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![42xel](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/42xel/32/1274_2.png) [@42xel](https://discuss.kakoune.com/u/42xel)\
**Post date:** [March 15, 2024, 1:19pm UTC](https://discuss.kakoune.com/t/move-anchor-and-cursor-together/2386/7 "2024-03-15T13:19:59Z")

</div>

I’ve solved this exact problem for [̶a̶u̶t̶o̶-pairs release](https://discuss.kakoune.com/t/a-u-t-o-pairs-release/2437) :

```auto
H<a-;>H<a-;>

```

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.

---

_[View the full topic](https://discuss.kakoune.com/t/move-anchor-and-cursor-together/2386)._
