micro icon indicating copy to clipboard operation
micro copied to clipboard

feature request : ability to navigate to previous position

Open wighawag opened this issue 5 years ago • 10 comments

Description of the problem or steps to reproduce

I am editing one file (or simply stay there for a while) at a certain line Then I jump either in the same file (maybe through search, or mouse) or in a different file /atb ...

I would like to go back to the previous position. There is no action I can bind that offer that currently.

Ideally we would have the following :

  • goBackInViewLocationHistory // this would let me go back to where I was looking
  • goForwardInViewLocationHistory // this would let me go back to my present location
  • goBackInEditLocationHistory // this would let me go back to where I was making my previous edit
  • goForwardInEditLocationHistory // this would let me go back to my latest edit

wighawag avatar Mar 08 '20 12:03 wighawag

Do you mean you'd like the ability to save a cursor position and push/pop back to that location?

I generally work around this by just memorizing what lines I'm working on (helps to have the ruler on), but I can see the advantage of a location stack or location history. Should be doable with a plugin.

sparques avatar Mar 08 '20 18:03 sparques

Here'a little POC plugin. I'll probably expand this some and integrate into the bounce plugin.

local storedLoc
-- store loc saves the cursors current position
function storeLoc(bp)
	storedLoc = -bp.Cursor.Loc
end

function gotoStoredLoc(bp)
	bp.Cursor:GotoLoc(storedLoc)
	bp.Cursor:Relocate()
end

Bind those functions to short cuts. For testing I just did CtrlG and CtrlK.

bind CtrlK "lua:bounce.storeLoc" bind CtrlG "lua:bounce.gotoStoredLoc"

So press CtrlK to keep a location and ctrl-g to goto it.

This only stores a single location, globally for all tabs, so lots of room for improvement. I'll probably work on enhancing this quite a bit more, as I can see this being really usefully in my daily workflow.

sparques avatar Mar 08 '20 18:03 sparques

Cool, This is not exactly what I want but it looks like I could dig deeper into plugin creation to achieve it.

What I want is that storeLoc is saved automatically, for example

  • when I edit some things. (I guess I can use onRune for that, right ? I did not see documented but could find it used by some plugin)
  • when I stay on the same position /line for a while. (I guess I can simply use some timer in my plugin to manage that)

Also ideally I would like the queue to be saved across restart. Is there an api for that ?

wighawag avatar Mar 09 '20 10:03 wighawag

By far the most common use I have for this is after jumping with Find. So the state could be saved in a stack, preferably only if a Find operation returns results. Also on click.

Odnes avatar Dec 10 '20 07:12 Odnes

It's not the full functionality you describe but I'm using the bounce plugin

ghost avatar Dec 10 '20 14:12 ghost

Cool, This is not exactly what I want but it looks like I could dig deeper into plugin creation to achieve it.

What I want is that storeLoc is saved automatically, for example

  • when I edit some things. (I guess I can use onRune for that, right ? I did not see documented but could find it used by some plugin)
  • when I stay on the same position /line for a while. (I guess I can simply use some timer in my plugin to manage that)

Also ideally I would like the queue to be saved across restart. Is there an api for that ?

@Odnes

You could change what Ctrl-F is bound to; you could set it to "CtrlF":"lua:bounce.storeLoc,Find"

So that the cursor location is saved. And then you can bind something to bounce.gotoStoredLoc to pop back to wherever you were when you hit Ctrl-F.

sparques avatar Dec 16 '20 17:12 sparques

@deusnefum Thank you so much for implementing cursor bounce!

mardukbp avatar Feb 09 '21 13:02 mardukbp

@mardukbp, Glad you find it useful! Just in case you or anyone finding this issue doesn't know: there's a better version in the official plugin stream plugin install bounce. Source is available at https://github.com/deusnefum/micro-bounce

sparques avatar Feb 09 '21 14:02 sparques

There's now also the bookmark plugin: https://github.com/haqk/micro-bookmark/

phil294 avatar Apr 24 '21 12:04 phil294

micro-bounce and micro-bookmarks are great but they are not what I am looking for here, I want something automatic, like I have in vscode where every time I change cursor position / file , it record it and I can go back there.

I had a another look on how I could achieve that with a micro plugin, but can't figure out. Is there a event I can hook into every time the cursor changes position or files ?

wighawag avatar Aug 23 '22 11:08 wighawag