I love working with Sublime Text, but one of its features annoys me sometimes which is "the accidental zoom in". Whenever that happens it breaks the momentum and I have to change it back to where it was and is kind of annoying. I searched for a shortcut which can reset the size back to normal but each one of them involved creating a python file and it does not work for me for some reason.
What would made my life much easier that if I could just change something in Preference.sublime-settings file and reset the font back to where I wanted it to be with just a shortcut key say "Control+0".
For background, Sublime Text 3 has commands named increase_font_size and decrease_font_size. These commands modify the font size up or down by some value (depending on what it is currently set to) and then directly modify the setting in the Preferences.sublime-settings file, which makes the change permanent everywhere.
These commands are bound by default to Ctrl+WheelUp/Down as well as Ctrl++ and Ctrl+-.
There exists a command reset_font_size (not bound to a key by default), but this command works by erasing the font size setting entirely; thus if you weren't using the default font size, this is unlikely to be useful. Additionally, this would also not reset any e.g. syntax specific font size.
There is a set_setting command which could be used to set the font size to one that you desire in a key binding, but this only modifies the font size of the current view (while the commands above make the change permanent globally), so this is a non-solution.
A solution that doesn't require a plugin to modify the behaviour would be to remove the binding from the mouse wheel entirely, or alter it so that it requires a different modifier key. That way it won't trigger by accident at all.
In order to do that, you need to create or modify the file Packages\User\Default.sublime-mousemap. In order to determine where your User package is stored, you can use Preferences > Browse Packages from the menu.
Something like the following stored as the contents of that file will remove the binding completely, so that font changes with the mouse wheel are not possible. If the file already exists, just add the second and third lines to the file, making sure that all entries end in a comma.
[
{ "button": "scroll_down", "modifiers": ["ctrl"], "command": "noop" },
{ "button": "scroll_up", "modifiers": ["ctrl"], "command": "noop" }
]
If you still want this functionality from the mouse, then you need a couple of extra lines to add the commands back. It's important that the two lines that map to the noop command remain; if you don't override them explicitly the defaults will remain.
Here's an example of requiring Shift and Control to both be held during a mouse scroll to modify the font size.
[
{ "button": "scroll_down", "modifiers": ["ctrl"], "command": "noop" },
{ "button": "scroll_up", "modifiers": ["ctrl"], "command": "noop" },
{ "button": "scroll_down", "modifiers": ["shift", "ctrl"], "command": "decrease_font_size" },
{ "button": "scroll_up", "modifiers": ["shift", "ctrl"], "command": "increase_font_size" }
]
Go to Preference->Settings and change the font size as you want....
Go to Preferences>keybinding
{ "keys": ["ctrl+shift+0",], "command": "reset_font_size" },
add this line at the last line before "]" in the right panel and save it.
Now every time you want to reset use this keyboard shortcut.
However, there isn't a keyboard shortcut for resetting the zoom/font size. Normally this would be super + 0(aka cmd + 0) in most apps, but Sublime Text doesn't give you this by default.
To get this feature you need to add the following to your keyboard bindings (found under Preferences -> Key Bindings)
{ "keys": ["super+0"], "command": "reset_font_size" }
Courtesy: coderwall.com
For Apple or MacOS, Press the Command Key -> ⌘) with either + or - key to increase or decrease text size in sublime accordingly
Press ctrl + to increase font and ctrl shift + to decrease font size.
I used and it works.
Related
Right now in order to perform a multi-cursor edit in SublimeText3 I press Ctrl and click the places I want to edit.
I want to change this so I press Alt (instead of 'Ctrl') and then click the places I want to edit.
I feeling like it should be somewhere in Preferences -> Key Bindings, but I was not able to find the option.
How can I change this key binding?
As the bindings here are for mouse buttons and not for keyboard keys, the actual bindings are not stored in sublime-keymap files and are instead stored in sublime-mousemap files. This is a format similar to a sublime-keymap file, but it includes the ability to map a command to mouse buttons, click counts and modifier keys.
Note: unlike a key binding, it's not possible to include a context key, so mouse bindings are an all-or-nothing affair; you can't set some to only apply in some circumstances and not others, for example.
In order to modify the mouse bindings you need to follow the same general procedure as you would for a key binding, which is to create a file with the appropriate name in your User package that includes your modified bindings. There aren't any default menu items or command palette entries that allow you to edit the mouse mappings, so you need to do this manually.
Note: In the following file names, $PLATFORM is one of Windows, OSX or Linux depending on what platform you're on (case is important). Your question doesn't mention which platform you're on, so the instructions below assume Windows; change the platform as needed for your own uses. On OSX your bindings can include super to represent the command key, as they can in key bindings.
Where the name of a key binding file is Default ($PLATFORM).sublime-keymap,the appropriate file for mouse bindings is Default ($PLATFORM).sublime-mousemap. Additionally, like most resource files that set the default behaviour, the base files are stored in the Default package.
If you use the View Package File command palette entry to open Default/Default (Windows).sublime-mousemap, you can see all of the default mouse bindings. There are two bindings in particular that you probably want to work with here, and they're near the top of the file in the "Basic drag select" section:
{
"button": "button1", "count": 1, "modifiers": ["ctrl"],
"press_command": "drag_select",
"press_args": {"additive": true}
},
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"subtractive": true}
},
The first binding says that when the Left mouse button (button1) is clicked a single time while the ctrl key is pressed, the drag_select command should be executed with an argument that indicates the selection should be added to.
Similarly, the second binding uses alt instead of ctrl and executes the same command, telling it to subtract from the selection instead of adding to it.
Thus, Ctrl+Left Click adds a caret (and any text you drag over) to the selection while Alt+Left Click does the reverse and removes carets and text you drag over.
To effect the change you want, create a file with the following contents and save it as Default (Windows).sublime-mousemap in your User package (you can use Preferences > Browse Packages to find where that is).
Note: If such a file already exists, add the two bindings here to the existing file instead of saving over it; in that case don't include the [ and ] characters, but make sure you paste the bindings in between the ones in the existing file along with the other bindings.
[
{
"button": "button1", "count": 1, "modifiers": ["alt"],
"press_command": "drag_select",
"press_args": {"additive": true}
},
{
"button": "button1", "count": 1, "modifiers": ["ctrl"],
"press_command": "drag_select",
"press_args": {"subtractive": true}
},
]
This is the two bindings from above, but with the modifiers swapped. That makes the Alt key add selections and Ctrl remove selection, effectively reversing their actions.
If you like you only need to add the binding for alt. However if you do that, the binding for ctrl will still exist, meaning you will have two bindings for adding a selection and no bindings for removing a selection. That may or may not be of concern depending on how much you rely on that particular binding.
Environment
Sublime Text: 3.1.1, Build 3176
Windows 10
Undesired Behaviour
I must have unintentionally pressed a keyboard combination as I have not had this issue before.
I cannot identify what circumstances create the undesired behavior, but sometimes this happens:
ie, I will be editing some text and realise that the cursor is in 2 (possibly more?) places and everything i am typing is also appearing in multiple places.
Edit: It seems to sometimes occurs after I have Ctrl + V / Ctrl + Shift + V pasted content.
What I've Tried
I've looked at this link, as the title sounded like it might be related:
https://www.sublimetext.com/docs/3/multiple_selection_with_the_keyboard.html
But on closer reading it doesn't seem to be.
I think the following answer might explain the behaviour, but not how to disable it:
https://stackoverflow.com/a/46800245
Desired Behaviour
I'd like to know how to disable the undesired behaviour.
Multiple Cursors on Sublime3, is activated by default either with
ctrl+left mouse button
or by
ctrl+shift+l
disabling ctrl+shift+l:
setting is called split_selection_into_lines. to disable it (Windows):
click Preferences, Key Binding, and on the file Default (Windows).sublime-keymap that will open add the line. (
{ "keys": ["ctrl+shift+l"], "command": "" },
be sure to put this inside the default brackets [ ].
Same is for Linux or Mac, only thing changes is the operating system name on the filename.
disabling ctrl+left mouse button:
Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User
Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User
Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User
open it with a text editor and paste the following lines in it:
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "",
"command": ""
}
]
Save and you are done. In my test, (win10, sublime text 3) method worked instantly, without even restarting Sublime Text 3.
I'm a long time VS user, and I have gotten used to doing the following in order to comment out multiple lines of code:
Ctrl+K and Ctrl+C
Likewise, uncommenting requires this:
Ctrl+K and Ctrl+U
Now I am switching to Sublime Text 3 for specific types of projects, and I would like to use the same bindings. I have transferred most bindings I commonly use, but I can't find a way to use the same "double" binding in Sublime. Is it possible?
And to be clear, of course I could un-learn the binding and use Sublime's, maybe even tweak VS to use that as well. However, I'd much rather use the one (ones?) I already know.
Go to Preferences -> Key Bindings
You will have 2 view layouts
for Default key bindings that sublime provides.
for user defined key bindings
Click on the user defined layout (right side layout) and write following code into the file to make comment using ctrl+k
[
{ "keys": ["ctrl+k"], "command": "toggle_comment", "args": { "block": false } }
]
I am running two Sublime windows at the same time. In one window I'm getting code to update the other one. Both are using the same color pattern, so I am confused between them.
My question is, is there a way to distinguish in between the windows? Making color-scheme different, or something like that?
This can be done with a very simple plugin and key binding. First, select Tools -> Developer -> New Plugin... and replace the contents with the following:
import sublime_plugin
class ChangeWindowColorSchemeCommand(sublime_plugin.WindowCommand):
def run(self):
for view in self.window.views():
view.settings().set("color_scheme",
"Packages/Color Scheme - Default/Cobalt.tmTheme")
You should change "Packages/Color Scheme - Default/Cobalt.tmTheme" to whichever color scheme you'd like to use in the window. Save the file as Packages/User/change_window_color_scheme.py - if you just go to File -> Save it should automagically open to Packages/User.
Next, create a new key binding by selecting Preferences -> Key Bindings-User and adding the following if the file is empty:
[
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" }
]
If you already have some custom key bindings, add the following on the line following the opening square bracket [:
{ "keys": ["ctrl+alt+shift+c", "s"], "command": "change_window_color_scheme" },
Save the file, and everything should be all set. Select the window you'd like to change the color scheme for, then hit CtrlAltShiftC, S - meaning you hit CtrlAltShiftC, release them, and hit S. You can change the key binding if you wish, of course.
I am trying to use the package "Alternate VIM Navigation" in ST3 on Linux Ubuntu, but the alt+i and alt+h keybindings bring up the find and help menus rather than their movement keybindings:
{ "keys": ["alt+i"], "command": "move", "args": {"by": "lines", "forward": false}},
{ "keys": ["alt+h"], "command": "move_to", "args": {"to": "bol", "forward": true}},
I have been able to disable the alt key from displaying the application menubar using CompizConfig Settings Manager, but the alt+i still brings up the find menu (and likewise for alt+h).
I have looked in many places for an answer to this, but have found nothing that works for ST3 in Linux. Here are some related answers for OSX and Windows, and an answer in Ubuntu that suggests the CompizConfig Settings Manager:
https://askubuntu.com/questions/553687/change-or-disable-modifier-key-alt-which-activates-the-application-menubar
Change behavior of Alt key in Sublime Text 2
Stop Alt key bringing up the menu in Sublime Text 2
Any solution to this in ST3 for Linux would be much appreciated!
This worked for me:
Open Sublime's packages directory by going to Preferences > Browse Packages.
Open the User directory and create a file called Main.sublime-menu
Paste the following in:
[
{
"caption": "Help",
"mnemonic": "",
"id": "help"
}
]
Save the file and enjoy!
I found a bit of a strange workaround...
I have a sublime text package called "SubRed" which has a file "Main.sublime-menu" (it's in .config/sublime-text-3/Packages/SubRed - I manually installed the package).
To disable the menubar all I have to do is:
ctrl+shift+p view: toggle menu (which does not disable the menu by
itself for some reason),
open the Main.sublime-menu file in sublime,
save it.
Then voila, the menu bar is gone and I can finally use my Alternate Vim package key bindings without conflicting with the alt+[menubar mnemonic].
To get the menu bar back if needed, just simply do ctrl+shift+p view: toggle menu.
If anyone could suggest a better solution based on this (which doesn't involve a random 3rd party package) that would be much appreciated!
The ideal solution would be to not have to disable the menubar, but get it to work like windows where user or package defined st3 keybindings take precedence over default or system bindings. So if "alt+i" is defined by the package as "move up a line", then it no longer opens the "Find" menu, but actually (eureka!) moves up a line! But opening the "Find" menu is still possible with "alt, i" in sequence.