Sublime Forum

Web browser-like history to go back to the previous focus

#1

When you work on a code, you usually work on 3/4 spots at the same time. You tweak, then you go to the next part, and you tweak, then you go back to the previous part. Then you click on another tab to check something. You scroll. You then go back, etc.

Having some ‘back’ and ‘forward’ arrows like in a browser would really ease this process. Every time you click on some part of a text file, it’s like when you enter a URL in the web browser: you change location, and the location get added to the history.

The history should go across tabs of course, as you usually edit several files at the same time.

0 Likes

Starting a new plugin
#2

Or you can use bookmarks, Ctrl+F2 to set a bookmark and F2 to jump back to them.

0 Likes

#3

Yeah, and you can use bookmark in a webrowser too. But would it be practical to not have history ?

0 Likes

#4

I don’t really see how this would work though. You’d have to keep a separate buffer to that of the “undo/redo” stack. And then how would they interlink?

0 Likes

#5

This is where the web browser analogy dies: URL are not supposed to change while your are browsing, while your code does.

The best I can think of is to save the last line number that lost focus and consider it “good enough”. It will be a time saver 99% of the cases since like in every history, the first and the second entry would be the most used. In the other cases, you will arrive far away from the edit and have to scroll as usual. It’s not a big deal, you just have to be aware of the limitation.

0 Likes

#6

XCode has this feature. I find it to be useful.

0 Likes

#7

Totally agree, this would be ultra-useful! Eclipse does it as well and I use it all the time to jump back and forth between bits of code. Would love to see this feature implemented.

I think I need to start poking around the API to see if this could be a plugin… ;]

0 Likes

#8

Try the “soft_undo” and “soft_redo” commands. Per default, both are mapped to “ctrl-u” and “ctrl+shift+u” and available from the “Edit”->“Undo Selection” menu.

0 Likes

#9

Now all we have to do is build it. :sunglasses:

0 Likes

#10

Yes, Open Komodo is full of useful, well tested, maintained code… The license for it, however, is MPL and GPL, which makes it impossible for Jon to bundle stuff from it into the ST2 official distribution… but we can always have plugins! :smiley:

0 Likes

#11

I created a patch against SublimeCodeIntel that can do this when you do “jump to definition” (alt+click or ctrl/cmd+f3).

It’s at github.com/optilude/SublimeCodeIntel for now, though I sent Kronuz a pull request.

I was thinking about whether to make it more general, e.g. have something that worked on every change of focus. But I’m not sure how to do it so that it doesn’t have a “back” action for every single movement of the caret, which seems pretty silly.

0 Likes

#12

Ok, I’ve created a plugin for this. See this thread. Hope it’s useful.

0 Likes

#13

That works great. Thanks.

0 Likes

#14

I would love to see this feature added. It should work just like in XCode 4. I find it’s my main mode of moving around. It needs to work between files as well as between significant edits in the same file. For example, if I’m working on a new call to function in file A, move to file B to define it, and file C to implement it. I then should be able to go back in ‘history’ twice to get back to file A.

0 Likes

#15

github.com/abrookins/GotoLastEdit/ has some of this functionality but right now sublime APIs are not sufficient. One can record focus changes and edits; in order to make plugin which matches eclipse, you need ability to record position at any command.

0 Likes

#16

I’m curious - how do others navigate between files?

0 Likes

#17

This feature would be the final blow to the competition…and a thing I am really missing in Sublime 2. BBEdit has this, and it’s called ‘Jump Forward and Jump Back’. Can press CMD-for back and CMD-Shft- to go forward.

Not necessarily does it have to deal with navigating around multiple documents (although that would be nice), but just in same document would be a good start. So often, I search and refer to a section of code, just to copy from it, or quickly mod it, but then need to get right back to where I was. I thought this was just my scatterbrained way of working, but seems other’s are accustomed to doing this too.

0 Likes

#18

I find the Caret-History plugin useful:

github.com/crazycooder/Caret-History

0 Likes