Wednesday, March 16, 2022

Re: Avoid jumping cursor after undo

On 2022-03-14, Lifepillar <lifepillar@lifepillar.me> wrote:
> I have defined this function:
>
> fun! Lint()
> let l:view = winsaveview()
> keepjumps normal gggqG
> call winrestview(l:view)
> endf
>
> When the function is executed, the cursor does not move, as expected.
> Unfortunately, pressing u after that makes the cursor jump to the top
> of the buffer. I had hoped that keepjumps would prevent that, but that
> does not seem the case. How can I avoid moving the cursor upon undoing
> (without touching registers)?

I have found a rational for this behaviour (Vim restores the position to
where the undone change has happened), and a way to keep the cursor
where it is:

https://vim.fandom.com/wiki/Restore_the_cursor_position_after_undoing_text_change_made_by_a_script

Perhaps, there is a less hackish way that does not modify the buffer.

Life.


--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/t0tc0t%2410vm%241%40ciao.gmane.io.

No comments:

Post a Comment