More than one sublime projects are open.
I zoom in for bigger fonts a file in one projects.
This zooms in fonts in all projects.
Can projects have different zoom independent of one another?
More than one sublime projects are open.
I zoom in for bigger fonts a file in one projects.
This zooms in fonts in all projects.
Can projects have different zoom independent of one another?
I guess you could use project specific settings for that:
Open Command Palette => Edit Project => add inside a “settings” section font_size:
"settings":
{
"font_size": 15,
}
Thank you,
but now I can not zoom in this project, I have to change this setting to change the size of font.
There is no way to do this in core Sublime by default, but this can be accomplished via a plugin. An example of that is the following plugin code that implements new versions of the commands for altering the font size that work only on the current window and leave the global preferences alone. It’s based on the default font commands that ship with Sublime.
To use the plugin you would either need to add key bindings to the new commands, or modify how the mouse reacts to input to allow you to execute the commands that way, or both.
For example, you could add the following key bindings:
{ "keys": ["ctrl+alt++"], "command": "increase_window_font_size" },
{ "keys": ["ctrl+alt+="], "command": "increase_window_font_size" },
{ "keys": ["ctrl+alt+-"], "command": "decrease_window_font_size" },
{ "keys": ["ctrl+alt+0"], "command": "reset_window_font_size" },
You can also add these commands to the mouse map so that you can use the mouse to zoom in a more natural way.
To do that, choose Preferences > Mouse Bindings
from the menu or, if you don’t see it there (it was added in a recent dev build so you may not see it unless you’re bleeding edge or reading this from the mysterious future), use View > Show Console
and enter the following to open the file.
window.run_command("open_file", {"file": "${packages}/User/Default (${platform}).sublime-mousemap"})
In the file, add the following content (if there is already content in the file, merge these entries with the existing content instead):
[
// Change window specific font size with ctrl+alt+scroll wheel
{ "button": "scroll_down", "modifiers": ["ctrl", "alt"], "command": "decrease_window_font_size" },
{ "button": "scroll_up", "modifiers": ["ctrl", "alt"], "command": "increase_window_font_size" },
// Reset the font size in this window back to the global default with a double click of the mouse wheel
{ "button": "button3", "modifiers": ["ctrl", "alt"], "count": 2, "command": "reset_window_font_size" },
]
If you’re not sure how to use plugins, see this video, which explains the process.
import sublime
import sublime_plugin
def get_window_settings(window):
"""
Get the settings dict from the window specific project data associated with
the given window; the return value is a dictionary that represents the
settings, which may be empty if this window has no settings yet.
"""
data = window.project_data() or {}
return data.get("settings", {})
def set_window_settings(window, settings):
"""
Set the settings dict for the window specific project data associated with
the given window to the settings object provided. This will replace the
current settings data in the window, if any.
"""
data = window.project_data() or {}
data["settings"] = settings
window.set_project_data(data)
class IncreaseWindowFontSizeCommand(sublime_plugin.WindowCommand):
def run(self):
w_settings = get_window_settings(self.window)
g_settings = sublime.load_settings("Preferences.sublime-settings")
current = w_settings.get("font_size", g_settings.get("font_size", 10))
if current >= 36:
current += 4
elif current >= 24:
current += 2
else:
current += 1
if current > 128:
current = 128
w_settings["font_size"] = current
set_window_settings(self.window, w_settings)
class DecreaseWindowFontSizeCommand(sublime_plugin.WindowCommand):
def run(self):
w_settings = get_window_settings(self.window)
g_settings = sublime.load_settings("Preferences.sublime-settings")
current = w_settings.get("font_size", g_settings.get("font_size", 10))
# current -= 1
if current >= 40:
current -= 4
elif current >= 26:
current -= 2
else:
current -= 1
if current < 8:
current = 8
w_settings["font_size"] = current
set_window_settings(self.window, w_settings)
class ResetWindowFontSizeCommand(sublime_plugin.WindowCommand):
def run(self):
w_settings = get_window_settings(self.window)
if "font_size" in w_settings:
del w_settings["font_size"]
set_window_settings(self.window, w_settings)
Thank you, that is quite a change. Also it changes Ctrl++ shortcut.
I was hoping that is some flag I could set for zoom not to interfere with other projects.
You can use whatever keys you want, the ones above are just defaults. It would also be possible to use the same keys and a context
that gates it behind a setting so that it would only apply in windows with projects open or what have you.
What am I doing wrong because this does not work for me.
When I do “Ctrl + +”, still font size in all project are changing.
I have added file
…sublime_text\Data\Packages\User\window_specific_font_size_keys.py:
[
{ "keys": ["ctrl++"], "command": "increase_window_font_size" },
{ "keys": ["ctrl+-"], "command": "decrease_window_font_size" },
{ "keys": ["ctrl+0"], "command": "reset_window_font_size" }
]
I add file
…\sublime_text\Data\Packages\User\window_specific_font_size.py
:
import sublime
import sublime_plugin
def get_window_settings(window):
data = window.project_data() or {}
return data.get("settings", {})
def set_window_settings(window, settings):
data = window.project_data() or {}
data["settings"] = settings
window.set_project_data(data)
There’s more plugin content than just the lines you outlined there (the code area scrolls within the page); are you sure you applied all of it?
You are right. Thank you.
I now add the full file for:
close all the projects, reopen and still all projects are changing font size.
no errors of both. When I add line and save I get just:
reloading plugin User.window_specific_font_size
reloading plugin User.window_specific_font_size_keys
The key bindings should not be in python plugin. Click on the menu Preferences
-> Key Bindings
and paste the code on the right hand side. Then, save the file.
That works for decrease but not for increase.
As ctrl + + does not work after I press ctrl + - .