I'm working with sublime 3 (build: 3143) and I experience a really annoying issue since a long time.
Whenever I type a backtick
`
it is automatically completed to a pair of quotes
`'
this is annoying especially when I want only one of the two symbols, and I'm not able to find what I did or wasn't able to prevent in order to obtain this higly undesirable behaviour.
I suspect this is something LaTeXTools is doing; no clue of what I shall disable (auto-completion? But then I'd lose autocompletions I need, and like, too).
Any help is welcome!
You're right, this is a keybinding from LaTeXTools:
// autopair quotation marks (`')
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`$0'"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
To remove this behavior, as there is no LaTeXTools preference for it, one can simply add a new keybinding in the User keybindings file to override it, that will simply insert a backtick:
{ "keys": ["`"], "command": "insert", "args": {"characters": "`"}, "context":
[
{ "key": "selector", "operator": "equal", "operand": "text.tex.latex"},
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true }
]
},
Related
Using sublime text. Similar to how when you add a new bracket { and hit enter, it creates a new indented block like so (the .... are spaces):
{
....
}
I would like the same thing to happen when I use backticks (since I'm using stlyed-components).
So when I input `+enter, I would get:
`
....
`
How do I do that?
You'll need a new keybinding for Enter, with specific conditions. Open Preferences → Key Bindings and add the following to the right side:
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Add Line in Braces.sublime-macro"}, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "`$", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^`", "match_all": true }
]
},
This will only run if you have the "auto_indent" setting on, the selection is empty, and the characters immediately before and after the cursor are backticks.
I tried to set the shortcut of Reindent in Sublime using the following approach:
{ "keys": ["ctrl+alt+i"], "command": "reindent", "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
]
},
So, now I would expect the Ctrl+Alt+i to Reindent the selected code. I checked that the file with keybindings is saved by reopening it.
But when I select all and press Ctrl+Alt+i re indentation does not happen.
Also I checked that the keybinding does not appear on the Reindent button.
I tried to restart the editor, but neither did this help.
What can I do about the issue? Thank you.
So the problem is to assign this to Escape without overriding any other functionality. I've tried the following, but it doesn't work.
{
"keys": ["escape"],
"command": "exec",
"args": {"hide_phantoms_only" : true },
"context": [ { "key": "phantom_visible", "operator": "equal", "operand": true }],
},
I haven't found any documentation on which context keys exist, so phantom_visible was just a guess.
Unfortunately, at the moment Sublime Text (at the time of writing, build 3126) does not have a context that you can use in a keybinding to tell when inline build error phantoms are shown. This has been briefly discussed in the ST forums so it is possible that a future build will contain this functionality.
In the meantime, inspired by this post, we could potentially try to create a keybinding that won't conflict with the default Esc behavior. But it's worth bearing in mind that the default keybindings may change so we will need to watch for it when updating ST, to see whether this is still relevant/correctly covers all scenarios:
{ "keys": ["escape"], "command": "exec", "args": { "hide_phantoms_only": true },
"context":
[
// inverse of all the "escape" key contexts found in the Default keybindings
{ "key": "num_selections", "operator": "equal", "operand": 1 },
{ "key": "has_next_field", "operator": "equal", "operand": false },
{ "key": "has_prev_field", "operator": "equal", "operand": false },
{ "key": "panel_visible", "operator": "equal", "operand": false },
{ "key": "overlay_visible", "operator": "equal", "operand": false },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}
I used Package Control to install Chain of Command, which allows me to do more than 1 command for each context.
When I press the [esc] key, now it does three things when the panel is visible:
Hides the panel
Hides the red error boxes
Kills the running program
Here is my key mapping for this:
[
{ "keys": ["escape"],
"context": [
{ "key": "panel_visible", "operator": "equal", "operand": true }
],
"command": "chain",
"args": {
"commands": [
["hide_panel", {"cancel": true}],
["exec", {"hide_phantoms_only": true}],
["exec", {"kill": true}]
]
}
}
]
Whenever I type ' in sublime it adds the terminating quote ' and places the cursor in the middle like this: '|'
Same goes for " that gets expanded into "|".
This is unwanted behavior for me, the only way I found to turn it off is by setting:
"auto_indent": false,
However, this makes it cumbersome to write indented code.
Is there anyway to get Sublime to not complete string literals and keep auto_indent?
I tested this on Sublime 3 Build 3114 on Windows and Sublime 3 Build 3083 on Linux.
The name of the setting should be auto_match_enabled as you see in definition in the default keybindings:
// Auto-pair quotes
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\"$0\""}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "[\"a-zA-Z0-9_]$", "match_all": true },
{ "key": "eol_selector", "operator": "not_equal", "operand": "string.quoted.double - punctuation.definition.string.end", "match_all": true }
]
},
I am working on a file which has syntax similar to something like:
name=...
line=...
line=...
line=...
...
I would like to make it so that when I am currently on a line that starts with "line=" that when I press "Enter" it will move to the next line and auto-populate it with "line=". Is there a way to do this with an EventListener with a plugin or possibly a way to do it with a snippet?
This key-binding will work:
{
"keys": [ "enter" ],
"command": "insert",
"args": { "characters": "\nline=" },
"context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "^line=", "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "$", "match_all": true },
]
},
Additionally, you can add a scope-specific context by appending something like the following line into the context array:
{ "key": "selector", "operator": "equal", "operand": "source.python", "match_all": true },
See: Sublime Text > Unofficial Documentation > Key Bindings for more information on context parameters.