Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When undoing, the cursor do not persist position #1

Closed
felippenardi opened this issue Oct 31, 2013 · 3 comments
Closed

When undoing, the cursor do not persist position #1

felippenardi opened this issue Oct 31, 2013 · 3 comments

Comments

@felippenardi
Copy link

Opening first Cosco issue on the Halloween 👻

I noticed that when I do a cosco action and undo it, my cursor do not comes back to where it was. Is it possible to ensure it will persist the position?

@lfilho
Copy link
Owner

lfilho commented Nov 1, 2013

Oooh halloween bug. Spooky!

Good catch, @felippenardi! Thanks! I will try to tackle it soon. Nevertheless, feel free to open a PR if you wish. :)

@lfilho
Copy link
Owner

lfilho commented Nov 1, 2013

So... I've been playing and researching a bit about this... I think this is actually in sync with the way vim works: if you execute a :s command (which is what cosco does under the hood) and then undo that :s, vim will automatically place the cursor in the beginning of the line.

It kind of makes sense when you think that you're executing an action in the whole line and then reverting the whole line modification.

To my basic VimL understanding, the only way to "cheat" this would be manipulate the undo tree, which I don't even think it's possible or make invisible steps, for example: going to insert mode, insert a char, delete it right after, and then executing the Cosco action (hence undo would go to the previous insertion point (which was were your cursor was).

But I'm not very keen on this solution as it may have undesired side effects as changing the user's jump list or maybe even make the command slower/noticeable in slower environments. And this a bad practice for plugins (to change vim's default behaviour). What do you think?

What I would suggest until we find a solution for this case is: after undoing (and vim placing your cursor in the beginning of the line), hit Ctrl-o to jump back to where you were.

I'd be happy to hear from more experienced vim scripters :)

@felippenardi
Copy link
Author

That makes sense! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants