Sublime Forum

Setting different font sizes for different tabs/files?

#1

Hello all,

A google search and search of this forum did not yield any relevant information on if it is possible to keep font sizes separate for different tabs/files. For example, if I have file1.txt open and file2.txt open, I would zoom in (using ctrl+"+") on file1.txt, but still see the normal default font size on file2.txt.

I read an article somewhere that it is possible to set the font size separately for different projects, but it is an immense pain to create a new project for just single files.

Does anybody know if there is a plugin or a way to change some settings to achieve this?

Thanks!

1 Like

Change font-size buggy and slow
#2

I have this problem too. My main use case is: Meeting involving projector (or screen shared with group). I want a Sublime window on the publicly-visible screen to have BIG text, while the rest of my windows retain their usual small text.

Another use case is running with multiple monitors of differing resolution. A Sublime window that gets dragged from one to the other will change size, and the text won’t be as readable. It’d be nice to bump just that one’s size up a bit.

There are others. Closely examining some text to try and spot differences (smart quotes, anyone?). Doing a screen shot and wanting things at a reasonable (to the receiver) size. Pair programming/troubleshooting and your coworker can’t read the text because they’re at a worse angle than you. Etc.

0 Likes

#3

The font size is controlled via the font_size setting and this is a setting that can be applied on a per view basis. An example of that would be using Preferences > Settings - Syntax Specific to open the settings for files of the type you’re currently editing and changing the font_size for files of that type independently of other file types.

If you only do this occasionally, you can use the Sublime console to tweak the font size on the fly. Focus the file that you want to change, open the console with View > Show Console and then enter view.settings().set("font_size", 20) to change the font size and view.settings().erase("font_size") to go back to the default.

For more generic use, you can use a plugin to provide commands that let you tweak this easily. For example, use Tools > Developer > New Plugin... to create a stub plugin, replace it with the below, and then save the result as a .py file in your User package (Sublime should default to there).

import sublime
import sublime_plugin


class IncreaseLocalFontSizeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        current = self.view.settings().get("font_size", 10)

        if current >= 36:
            current += 4
        elif current >= 24:
            current += 2
        else:
            current += 1

        if current > 128:
            current = 128

        self.view.settings().set("font_size", current)


class DecreaseLocalFontSizeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        current = self.view.settings().get("font_size", 10)

        if current >= 40:
            current -= 4
        elif current >= 26:
            current -= 2
        else:
            current -= 1

        if current < 8:
            current = 8

        self.view.settings().set("font_size", current)


class ResetLocalFontSizeCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        self.view.settings().erase("font_size")

With that in place, you can set up key bindings for the commands. For example:

{ "keys": ["alt+ctrl+="], "command": "increase_local_font_size" },
{ "keys": ["alt+ctrl+-"], "command": "decrease_local_font_size" },
{ "keys": ["alt+ctrl+0"], "command": "reset_local_font_size" },

You could also use this plugin that provides a toggle_setting_ext command to easily toggle between a fixed list of font sizes:

{
    "keys": ["alt+ctrl+f"],
    "command": "toggle_setting_ext",
    "args": {
         "setting": "font_size",
         "options": [10, 20]
     }
},

In this case you either need to include your normal font size in the list of values or use the command from above to reset it.

3 Likes

Set a default zoom and use Ctrl + 0 to reset?