Sublime Forum

Different font sizes for different windows

#1

Hello,
Is it possible to have different font sizes for different windows ?

Thanks.

2 Likes

#2
  • You can have different settings for different projects. This is probably what you want.
  • You can have different settings for different views. This is trickier and also transient, so more of a temporary thing.
3 Likes

#3

It is possible for each view to have its own font size. However, the Sublime core does not provide an easy interface for changing per-view font sizes.

To see this in action, open up the Python console (ctrl-`) and run the following command:

view.settings().set("font_size", 20)

If you like, you can create a Sublime command that will do this and bind that command to a key. Something like this:

import sublime
import sublime_plugin

class ChangeViewFontSizeCommand(sublime_plugin.TextCommand):
    def run(self, edit, by):
        settings = self.view.settings()
        settings.set("font_size", settings.get("font_size") + by)

And for the keymap:

[
    {
        "keys": ["ctrl+shift+="],
        "command": "change_view_font_size",
        "args": {
            "by": 1,
        }
    },
    {
        "keys": ["ctrl+shift+-"],
        "command": "change_view_font_size",
        "args": {
            "by": -1,
        }
    },
]

Now, this will work per-view, not per-window. You can’t directly set font size at the window level. The easiest way to do what you want is to use project settings (as braver mentions). But you could do something more complicated:

import sublime
import sublime_plugin

class ChangeWindowFontSizeCommand(sublime_plugin.WindowCommand):
    def run(self, by):
        window_settings = self.view.settings()
        global_font_size = sublime.load_settings('Preferences.sublime-settings').get('font_size')

        window_font_size = window_settings.get('window_font_size', global_font_size) + by
        window_settings.set('window_font_size', window_font_size)

        for view in window.views():
            view.settings().set('font-size', window_font_size)

class WindowFontSizeListener(sublime_plugin.EventListener):
    def on_new(view):
        window_settings = view.window().settings()
        if window_settings.has('window_font_size'):
            view.settings().set('window_font_size', window_settings.get('window_font_size'))

This uses a custom window-level setting called window_font_size. When the change_window_font_size command is invoked, we update this setting, then set the font size of each view in the window. When a new view is created, if its window has a window_font_size setting, we set the font size of the new view.

3 Likes

#4

Thanks for your answers.

@braver, I should have done this by setting this in different projects.
But I was thinking in term of view.

Thanks to @ThomSmith who gave the solution, I just have to follow his instructions.

In fact, during some of my lessons, I use TerminalView to

  • compile LaTeX files with pythontex
  • execute c/c++ programs
  • demonstrate shell script during training
  • run interpreted languages in an interpreter

I just need to have the programs readable from far
but the shell result have to be executed by the students on their computer.

So, I don’t need to have any other terminal program.

1 Like

#5

I also found problems with @ThomSmith answer, as variables used but not declared.

This is a variation of @ThomSmith answer, where it supports settings inheritance from the current window, in case you create a new window with Ctrl+Shift+N:

Then, create these keybinds:

	{ "keys": ["ctrl++"], "command": "increment_setting", "args": {"setting": "font_size", "increment": 1} },
	{ "keys": ["ctrl+-"], "command": "increment_setting", "args": {"setting": "font_size", "increment": -1} },

I built this mostly as a copy-paste from this other thread:

0 Likes

On_load is not triggered in a new view with Ctrl+N
#6

yes it is possible to have different font size for different windows.

1 Like