Sublime Forum

How to make Ctrl+PgUp/PgDown only cycle the current panel?

#1

Edited question because i am confused

Sorry, my head was in another place, so the original question is wrong.

What i wanted to ask is if i could get the behaviour of cycling only the tabs in the currently-focused panel, when using Ctrl+PgUp and Ctrl+PgDown to cycle?

This is because my default cycling order is most-recently used (for Ctrl+Tab). So when i want to cycle them in order, i use Ctrl+PgUp/PgDown; in which case they will currently cycle them through both panels. But i would want them to cycle, in order, only the focused panel.

Is that possible?

Original question

I don’t know the correct term, but when you split the editor via the View > Layout > Columns:2 (or Rows:2), those two individual rows or columns that can show different files is what i’m gonna refer to as panels.

Currently, when i cycle through tabs with Ctrl+Tab, it will always cycle all open tabs, regardless that they may be in different panels. When it reaches the end of the right panel, it will shift focus to the left one and continue cycling those.

What i would like is for it to only cycle the tabs of the panel which currently has focus. Meaning if my right panel currently has focus, then Ctrl+Tab will leave the left panel as-is, and only cycle the tabs of the right panel.

0 Likes

#2

Unless you have a plugin ST has always just cycled through the tabs in the current panel.

0 Likes

#3

Yes you are right, i confused myself as i was writing the question, so that was super incorrect.

I have edited the question now to ask what i really meant in the first place.

0 Likes

#4

If you use ctrl + pageup or ctrl + pagedown, then it correctly cycles through the tab in order (forward/backwards respectively) only in the currently focused “panel” (to use your terminology, they are actually referred to as groups, panels have a different meaning in ST) even if the user has multiple layouts in the editor pane.

Could you perhaps share a GIF of what the behavior is (along with a set of steps performed) in your setup ?

0 Likes

#5

Ok, here is a video: https://streamable.com/kxx5oh

So this is a brand new open instance of Sublime text. What i do exactly, in order, is:

  1. Press my shortcut for creating a 2-column view (keybind config below)
  2. Type stuff
  3. Hit Ctrl+N
  4. Type stuff
  5. Press my shortcut to focus on the first group (config below)
  6. Type stuff
  7. Hit Ctrl+N
  8. Type stuff
  9. Spam Ctrl+PgUp a bunch of times

So what’s visible there is that it cycles both groups (which is what i want it not to do, and as you pointed out, it shouldn’t). I don’t think any other custom keybinds are relevant, i don’t have a custom keybind for anything relating to PgUp. I also don’t think any of my plugins would interfere with this, the only plugins i have are Emmet, ESLint, PlainTasks, and SFTP.

Keybind config for the 2-column view:

	{
		"keys": ["ctrl+,"],
		"command": "set_layout",
		"args":
		{
			"cols": [0.0, 0.5, 1.0],
			"rows": [0.0, 1.0],
			"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
		}
	},

Keybind config for focusing the first group:

     { "keys": ["alt+;"], "command": "focus_group", "args": { "group": 0 } }
0 Likes

#6

I thought this should work this way by default too, but it looks as though the behviour of the next_view and prev_view commands was altered in ST4.

In a fresh copy of ST3 build 3211, indeed in a split view the default key bindings go through all views in all panes, but in ST4 build 4094 they constrain the views to the current group only. This seems to be true all the way back to 4050 as well.

I’m not aware of any setting that controls this however. So in ST3 you likely need a plugin to implement the commands in a way that constrains them.

0 Likes

Sublime text 4 - how to emulate/restore shortcut to cycle through all tabs (not just in current focus group) as per ST3
#7

Indeed. Just checked in a fresh ST3 3211 portable install that next_view & prev_view cycles through all of the views across all groups.

In ST4, however, the cycling is constrained to the currently focused group.

But as OdatNurd mentions that a plugin can help and indeed since the ST Python API (the Window class in particular) provides a user with all the tools necessary to do the desired behavior, it’s actually trivial to write 2 simple commands that does what next_view & prev_view does but only restrain them in the current group.

import sublime
import sublime_plugin

class CycleNextCommand(sublime_plugin.WindowCommand):

    def run(self):
        views = self.window.views_in_group(self.window.active_group())
        cur_view_index = self.window.get_view_index(self.window.active_view())[1]

        if cur_view_index == len(views) - 1:
            self.window.focus_view(views[0])
        else:
            self.window.focus_view(views[cur_view_index + 1])

class CyclePrevCommand(sublime_plugin.WindowCommand):

    def run(self):
        views = self.window.views_in_group(self.window.active_group())
        cur_view_index = self.window.get_view_index(self.window.active_view())[1]

        if cur_view_index == 0:
            self.window.focus_view(views[len(views) - 1])
        else:
            self.window.focus_view(views[cur_view_index - 1])

Save this file as a python file (with any name you want e.g. foo.py doesn’t matter) in the User directory (Preferences -> Browse Packages from main menu to get to User).

Then have 2 simple keybindings to override ctrl + pageup & ctrl + pagedown in your user keybindings file.

[
	{
		"keys": ["ctrl+pageup"],
		"command": "cycle_next"
	},
	{
		"keys": ["ctrl+pagedown"],
		"command": "cycle_prev"		
	}
]

The commands do the following :-

  1. The cycle_next is the same as next_view (cycles through the tab in a forward linear manner) but it does it only for the currently focused group.
  2. The cycle_prev is the same as prev_view (cycles through the tab in a backwards linear manner) but it does it only for the currently focused group.

Hopefully, this helps

4 Likes

#8

It works! I can’t believe you actually wrote me a plugin, that’s amazing. If i had 2 cookies right now, i would give you both of them. Thank you so much!

1 Like

#9

Haha… your welcome. Enjoy the cookies and coding in Sublime Text.

2 Likes

#10

Also available as a package https://packagecontrol.io/packages/BetterTabCycling

0 Likes

#11

Yes. I know there would be some package that does this but making the plugin hardly took 5 minutes, so … went with making my own solution.

0 Likes