It’s easily possible to change the font size of an individual view
(file) to be different than what would be used by default (see plugin below). Assigning a custom font size to a particular panel(view group) isn’t as easy to pull off, though.
In particular a plugin like the below could use view.window()
to get the window
that it’s contained in, then use window.active_group()
to get the group (i.e. “panel”) that the view is contained in and apply the appropriate settings change to all of the views reported by window.views_in_group()
so that all of the files in that section of the window would change at once.
However as evidenced below the font size is really a view by view setting, so moving a tab to that group won’t apply the group font size to it, nor will the font size be changed back to the default if you move a tab out.
As far as I’m aware the only way to reliably detect when a file tab is moved between groups would be to continuously check with the above API calls and see when a view is in a different group than it was in last time, which is probably not that great for performance. There may be a better way to do that, though.
Of course if that doesn’t bother you and you don’t mind manually managing the font when the files in the group are changing, that may not matter.
In any case, the following is a plugin that implements view specific versions of the standard commands for changing the font size, which affect things globally. In fact this is just a modified version of the Default/font.py
plugin that ships with Sublime by default.
To use it you would select Tools > Developer > New Plugin...
from the menu, then replace the stub code with the code here and save it in the location that Sublime defaults to as a python file (I called mine view_font.py
):
import sublime
import sublime_plugin
class IncreaseViewFontSizeCommand(sublime_plugin.TextCommand):
def run(self, edit):
s = self.view.settings()
current = s.get("font_size", 10)
if current >= 36:
current += 4
elif current >= 24:
current += 2
else:
current += 1
if current > 128:
current = 128
s.set("font_size", current)
class DecreaseViewFontSizeCommand(sublime_plugin.TextCommand):
def run(self, edit):
s = self.view.settings()
current = s.get("font_size", 10)
# current -= 1
if current >= 40:
current -= 4
elif current >= 26:
current -= 2
else:
current -= 1
if current < 8:
current = 8
s.set("font_size", current)
class ResetViewFontSizeCommand(sublime_plugin.TextCommand):
def run(self, edit):
s = self.view.settings()
s.erase("font_size")
With that in place, you can create your own key bindings that use these commands. For example:
{ "keys": ["shift+ctrl++"], "command": "increase_view_font_size" },
{ "keys": ["shift+ctrl+="], "command": "increase_view_font_size" },
{ "keys": ["shift+ctrl+-"], "command": "decrease_view_font_size" },
This is just the default key bindings with a Shift added, but you could use whatever you want. You can also bind something to the reset_view_font_size
command to set it back to the original font, or add it to the view context menu, etc.