Sublime Text: Font Size per File
By default, changing the font size in Sublime Text, changes the font size in all windows.
Sometimes you want more granular control, e.g. when sharing your screen on a conference call.
It is easy to create a custom Plugin, that lets you increase or decrease the font size of each individual file, and easily revert back to the default setting.
Custom Plugin
- In the Sublime toolbar, go to “Tools” > “Developers” > “New Plugin…”
This opens a new file with a skeleton of a plugin. - Replace the file contents with this code:
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)
class ResetLocalFontSizeCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.settings().erase("font_size")
Save this file as change_view_font_size.py
3. Copy the extension into the Sublime folder for User packages:
cp change_view_font_size.py ~/Library/Application\ Support/Sublime\ Text/Packages/User/
4. In the Sublime toolbar, go to “Settings…” > “Key Bindings” and add these lines to your sublime-keymap
file:
[
{ "keys": ["command+shift+="], "command": "change_view_font_size", "args": {"by": 1} },
{ "keys": ["command+shift+-"], "command": "change_view_font_size", "args": {"by": -1} },
{ "keys": ["command+shift+0"], "command": "reset_local_font_size" },
]
Changing Font Size of one File
Now when you type ⌘ ⇧ =
or ⌘ ⇧ -
, the font size of the specific file you are in will increase or decrease accordingly.
You can reset the font size to the default by typing ⌘ ⇧ 0
enjoy! 😃