Sublime Forum

Is there a way to toggle between the last two files with a single shortcut?

#3

Seems to do what I want but would be better if I could do it with a single shortcut.

0 Likes

#4
  1. To go to the menu Preferences -> Browse Packages...
  2. Create the folder Toggle Last Files
  3. Create the file Toggle Last Files/main.py and put inside it:
import sublime
import sublime_plugin

isToggled = False

class ToggleBetweenTheLastTwoFilesCommand( sublime_plugin.TextCommand ):
    """
        toggle_between_the_last_two_files
    """

    def run( self, edit ):
        global isToggled
        window = self.view.window()

        if isToggled:
            isToggled = False
            window.run_command( "prev_view_in_stack" )

        else:
            isToggled = True
            window.run_command( "next_view_in_stack" )
  1. Create the file Toggle Last Files/Default.sublime-keymap and put inside it:
[
    { "keys": ["ctrl+shift+o"], "command": "toggle_between_the_last_two_files" }
]

Then just press ctrl+shift+o and it will toggle between the last two files.

1 Like

#5

Thanks. Though it doesn’t seem to work all the time, sometimes it activates an older window. I guess that’s a problem with the next/prev_view_in_stack. Will investigate some more.

1 Like

#7

Isn’t ctrl+tab what you want? it’s the same as alt+tab on windows, except it’s for tabs.

0 Likes

#8

keyboard: ctrl+pageup & ctrl+pagedown
or
mouse: back & forward buttons

0 Likes

#9

As pointed, but deleted, it was not working because you need to save the change state per window.

But it is easier just use Ctrl+Tab.

0 Likes

#10

next_view_in_stack (i.e., ctrl+tab) is what you want. Don’t forget to let go of ctrl afterwards though, as it’s only then that the stack gets updated.

5 Likes

#11

It would be nice if there was a preview of the stack while ctrl is hold, just like in windows with alt+tab. I cannot remember the order in which I used my tabs and the lack of a preview makes browsing through the stack feel very random. It wouldn’t need an image, just the tab name (with the folder name appended for files with the same name) would be enough.

4 Likes

#12

I opened a issue for it on the Core Issue tracker:

  1. Core$1789 Preview of the stack while Ctrl on Ctrl+Tab is held down
1 Like

#13

I don’t think it has to do with the state per window as I was using a single window and it jumped to older files instead of toggling only between the last 2 activated files. I’m currently working on a plugin that will keep track of the last activated files manually but I’m currently stuck as I can’t tell whether an active view is the quick panel (and this messes things up) - I don’t have much experience with the Sublime Text API.

0 Likes

#14

Something else, because someone mentioned not holding down the Ctrl key. For the plugin above actually it only worked fine if I held down the Ctrl key; if I released it, the next time I triggered the command it switched me to an older (incorrect) tab.

0 Likes

#15

PS: I figured out how to check if a view is a “standard” view; I can just check whether it’s in self.window.views()

1 Like

#16

I’m not sure if it’s more efficient but I saw a plugin view.settings().('is_widget') If true, it’s not a normal view.

1 Like

#17

You don’t need a plugin, just press ctrl+tab to switch between the two most recently used files

0 Likes

#18

I can’t use Ctrl+Tab, as I’ve reassigned those to:

{ "keys": ["ctrl+tab"], "command": "next_view" },
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" },

because that makes more sense. Now they move to the next/previous tab as seen in the window. Previously the behavior didn’t make much sense to me. Do you know which command was previously assigned to Ctrl+Tab? Just curious if I could do this without the plugin (which by the way is done now and works fine - I will make it public soon).

0 Likes

#19

PS: I’ve removed my ctrl+tab/ctrl+shift+tab keybindings and no, it doesn’t work as I want it. Maybe you meant to use ctrl+tab and then ctrl+shift+tab to move back? This is not what I want, I want a single key combination to toggle between the last two files (which I’ve done with my plugin).

0 Likes

#20
  1. If you press Ctrl+Tab one time, and release the Ctrl and Tab keys, it will switch to the last used tab.
  2. If you press Ctrl+Tab one time, and release the Ctrl and Tab keys, it will switch to the last used tab.

So, you will always be using the some key stroke combination to switch between the last two tabs.

It is not this what you want to?

0 Likes

#21

Indeed seems to work (apparently I didn’t release Ctrl). The command it seems is “next view in stack”. But I will continue to use my plugin as I don’t have to release the Ctrl key for it to work.

0 Likes

#22

OT, but what tool did you use to visualize the pressed keys? I’ve been looking for something like that. Not actively but for quite a while now. (Ideally for linux, too.)

0 Likes

#23

I found it by accident the other day, the programs used are:

  1. https://github.com/Phaiax/PxKeystrokesForScreencasts (Windows only)
  2. https://github.com/justinfrankel/licecap (Windows and Mac only)

For linux you may try:

  1. https://github.com/critiqjo/key-mon
  2. https://github.com/wavexx/screenkey
  3. https://github.com/scs3jb/screenkey/network
  4. https://github.com/phw/peek
0 Likes