Avoid quote autocomplete in sublime text when backslash is inserted - autocomplete

I am writing a latex document and I want to insert accented characters..
Suppose I want to insert accented e: è
If I want to write it I use:
\`e
But with sublime autocomplete, when I insert the backquote I get
\`e`
So I have to delete the extra backquote each time I insert an accented character.. Is there a way to avoid closing quote if the first quote is preceded by a backslash?
Thanks

Try adding the following to your user key bindings.
{ "keys": ["'"], "command": "insert_snippet", "args": {"contents": "'"}, "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.single", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.tex", "match_all": true }
]
}
I took the existing key binding for auto pairing quotes in the default key bindings. I then changed the snippet so it would simply enter a single character. You could change it to an insert command but it doesn't really matter. I then added the last 2 entries to context. The first checks the preceding text for \. The second restricts the key binding to files that have a scope of text.tex.latex. The second entry isn't really necessary, but if it's not there, it will apply to all file types, not just tex files.
edit
Double quote solution
{ "keys": ["\""], "command": "insert_snippet", "args": {"contents": "\""}, "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", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.tex", "match_all": true }
]
}
To reiterate, I started with the double quote auto pair key binding (from the defaults), and added the two context entries. Failing to parse means you had some malformed json. If I had to guess, you had to many/not enough \ escapes.
edit2
Same procedure. Hopefully I got the right quote this time :)
{ "keys": ["`"], "command": "insert_snippet", "args": {"contents": "`"}, "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 },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\\\$", "match_all": true }
]
}

Related

vscode define select n lines shortcut

I have some custom shortcuts to move with cmd+up and cmd+down with intervals of 5 lines.
{
"key": "cmd+up",
"command": "cursorMove",
"args": {
"to": "up",
"by": "line",
"value": 5
},
"when": "editorTextFocus"
},
{
"key": "cmd+down",
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 5
},
"when": "editorTextFocus"
},
What I would like is when pressing shift+cmd+[up,down] to select 5 lines up and down. I've found that there are a few "commands" such as {cursorDownSelect, cursorPageDownSelect, CursorEndSelect} but none of them allow me to define some args to jump a few lines, does anybody know how to do it ?
You can add the select option to the cursorMove command. Search for cursorMove at this commands page: https://code.visualstudio.com/api/references/commands
{
"key": "cmd+up",
"command": "cursorMove",
"args": {
"to": "up",
"by": "line",
"value": 5
"select": true // the default is false
},
"when": "editorTextFocus"
},
{
"key": "cmd+down",
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 5,
"select": true
},
"when": "editorTextFocus"
}

Disable autocomplete on tab

After update from sublime text 3 autocomplete triggers on TAB and ENTER
Its hard to use snippets like foreach in PHP
foreach($mark as $mark => $mark) {
$mark
}
In sublime text 3 after TAB you jump to next mark, but now autocomplete happens
I tried some settings
"tab_completion": false,
"auto_complete_commit_on_tab": false,
Not working
Found key binding
{ "keys": ["tab"], "command": "commit_completion", "context":
[{ "key": "auto_complete_visible" }]
},
Dont know how to remove it
Pls help, its too hard to use Sublime text now
I tried some solutions, there are not perfect. There is a worked solution: [SOLVED] ST3: “tab_completion”: false does not work,
but now I want to provide mine (inspired by this link ↑, thanks for #OdatNurd).
1. Preferences -> Key Bindings
2. Search '"keys": ["tab"]' at left window, then you get a group of result. It's look like this for me:
{ "keys": ["tab"], "command": "auto_complete", "args": {"mini": true, "default": "\t"},
"context":
[
{ "key": "auto_complete_visible", "operand": false },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": ".*\\w", "match_all": true },
]
},
{ "keys": ["tab"], "command": "expand_snippet", "context":
[{ "key": "has_snippet" }, ]
},
{ "keys": ["tab"], "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 }
]
},
{ "keys": ["tab"], "command": "indent", "context":
[{ "key": "text", "operator": "regex_contains", "operand": "\n" }]
},
{ "keys": ["tab"], "command": "move", "args": {"by": "lines", "forward": true}, "context":
[
{ "key": "overlay_has_focus", "operator": "equal", "operand": true }
]
},
{ "keys": ["tab"], "command": "next_field", "context":
[{ "key": "has_next_field", "operator": "equal", "operand": true }]
},
{ "keys": ["tab"], "command": "commit_completion", "context":
[{ "key": "auto_complete_visible" }]
},
(I don't want to imply what it should look like, because different sublime versions will have different settings.)
3. COPY them all into the right window.
4. DELETE (or just Comment Out) both "auto_complete" block and "commit_completion" block at right the window, and don't change anything else. Now, my User Keybindings like this:
// Disable all autocompletion and tab completion. This overrides the default
// binding for this key.
{ "keys": ["tab"], "command": "insert", "args": {"characters": "\t"} },
// { "keys": ["tab"], "command": "auto_complete", "args": {"mini": true, "default": "\t"},
// "context":
// [
// { "key": "auto_complete_visible", "operand": false },
// { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
// { "key": "setting.tab_completion", "operator": "equal", "operand": true },
// { "key": "preceding_text", "operator": "regex_match", "operand": ".*\\w", "match_all": true },
// ]
// },
{ "keys": ["tab"], "command": "expand_snippet", "context":
[{ "key": "has_snippet" }, ]
},
{ "keys": ["tab"], "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 }
]
},
{ "keys": ["tab"], "command": "indent", "context":
[{ "key": "text", "operator": "regex_contains", "operand": "\n" }]
},
{ "keys": ["tab"], "command": "move", "args": {"by": "lines", "forward": true}, "context":
[
{ "key": "overlay_has_focus", "operator": "equal", "operand": true }
]
},
{ "keys": ["tab"], "command": "next_field", "context":
[{ "key": "has_next_field", "operator": "equal", "operand": true }]
},
// { "keys": ["tab"], "command": "commit_completion", "context":
// [{ "key": "auto_complete_visible" }]
// },
Enjoy it 🎉. This solution won't break the snippets index, and you can commit completion with enter.
Not sure how portable the solution is (especially with regards to different versions of Sublime). I'm on Linux (Fedora 34) and using the latest Sublime from their official repo (build 4121 at time of writing) with a registered license.
But I think the issue I had was similar to yours (your post was the first duckduckgo result for "sublime disable auto complete on tab"). Basically, I already had auto_complete and auto_match_enabled both set to false in my preferences file but was still seeing that if I had some text such as:
async: false,
and I placed my cursor after the "c" in async and hit TAB that it would try to autocomplete this to some word that began with "async". But the behavior that I wanted was for it to literally insert a TAB (\t) character instead of using TAB as auto-completion trigger.
After reading this post, I tried "auto_complete_commit_on_tab": false which didn't seem to work for me either. I couldn't figure out how to override the selector keybinding so I started disabling a lot of auto-complete settings in a "shotgun approach". I did search online for settings but mostly just went off of the descriptions in the global / left-hand side of the settings file.
I'm not sure of the exact setting that did it but it now behaves as I wanted with TAB just inserting a \t character. I suspect that "auto_complete_size_limit": 1 may have been the most relevant setting but I'm not sure.
Here is my preferences file for reference:
{
"always_prompt_for_file_reload": true,
"atomic_save": true,
"auto_close_tags": true,
"auto_complete": false,
"auto_complete_size_limit": 1,
"auto_complete_selector": "",
"auto_complete_commit_on_tab": false,
"auto_complete_with_fields": false,
"auto_complete_cycle": false,
"auto_complete_use_index": false,
"auto_complete_use_history": false,
"auto_complete_trailing_symbols": false,
"auto_complete_include_snippets": false,
"auto_complete_include_snippets_when_typing": false,
"auto_match_enabled": false,
"copy_with_empty_selection": false,
"drag_text": false,
"detect_indentation": true,
"ensure_newline_at_eof_on_save": true,
"font_size": 15,
"highlight_modified_tabs": true,
"show_encoding": true,
"show_line_endings": true,
"tab_completion": false,
"translate_tabs_to_spaces": false,
"trim_automatic_white_space": true,
"trim_trailing_white_space_on_save": true,
"update_check": false,
"close_find_after_find_all": false,
"close_find_after_replace_all": false
}
I believe what you're looking for is tab_completion: false. When I added this to my preferences, and typed some text and hit tab, it no longer pops up an auto-complete modal, and just inserts \t like I wanted it to.

Scrolling up or down with ctrl moves cursor to first non whitespace

When I scroll using ctrl + up/down, the cursor is moved to the first non-whitespace character on the line, when it goes outside of the view. This is a bit annoying when I've placed the cursor in the left-most column on purpose (this is how I edit, sometimes).
You can see the effect more clearly with this keybinding:
[
{
"key": "ctrl+down",
"command": "editorScroll",
"args": {
"to": "down",
"by": "line",
"revealCursor": true
}
},
{
"key": "ctrl+up",
"command": "editorScroll",
"args": {
"to": "up",
"by": "line",
"revealCursor": true
}
}
]
Can I toggle this behaviour off so that the cursor stays in the column where I've placed it?
If you want to use keyboard scrolling while keeping the cursor position at the same column, one workaround would be to use the macros extension so that you can both scroll down and move the cursor down at the same time.
Add this to settings.json
"macros": {
"keyboardScrollDown": [
{
"command": "editorScroll",
"args": {
"to": "down",
"by": "line",
"revealCursor": true
}
},
"cursorDown"
],
"keyboardScrollUp": [
{
"command": "editorScroll",
"args": {
"to": "up",
"by": "line",
"revealCursor": true
}
},
"cursorUp"
]
},
Add this to keybindings.json
{
"key": "ctrl+down",
"command": "macros.keyboardScrollDown"
},
{
"key": "ctrl+up",
"command": "macros.keyboardScrollUp",
},

Sublime text autocomplete wth tab key only after character

Can Sublime text 3 be configured to do autocomplete when hitting the tab key only when the cursor is after a character and not before?
I want to avoid the -done completion and I want to add a tab space instead.
As you've experienced, ST's default behavior is to "insert the best completion" when the caret is only preceded by whitespace on the line.
Fortunately, ST is very customizable, and we can override this behavior, to that which you desire.
To do so, add this to your user keybindings:
{ "keys": ["tab"], "command": "indent",
"context":
[
{ "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "not_regex_match", "operand": "^$", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
]
},
{ "keys": ["tab"], "command": "insert", "args": { "characters": "\t" },
"context":
[
{ "key": "preceding_text", "operator": "regex_match", "operand": "^\\s*$", "match_all": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
]
},
This tells ST that, when you press Tab, it should indent the text when the following are true:
- there is no selection
- the caret is at the beginning of the line or only preceded by whitespace (i.e. indentation)
- there is some text after (/ to the right of) the caret
- the auto-completion popup is not visible
Also, when all those conditions are true except that there is text on the line after the caret, we tell ST to insert a tab character. Note: ST will translate that to the correct number of spaces if you are using spaces for indentation.
(The old behavior of indenting when you press Tab with a multi line selection will stay, as will the other default bindings when our conditions are not met.)

Sublime Text 2: trying to escape the dollar sign

I'm trying to define a keybind in Sublime to have it autopair the dollar sign, "$", in the same way it autopairs the following symbols:
"
(
[
{
'
I opened the default keymap file and added the following code:
// Auto-pair dollar signs
{ "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", "match_all": true }
]
},
{ "keys": ["\$"], "command": "insert_snippet", "args": {"contents": "\$${0:$SELECTION}\$"}, "context":
[
{ "key": "setting.auto_match_enabled", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
},
{ "keys": ["\$"], "command": "move", "args": {"by": "characters", "forward": true}, "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": "^\$", "match_all": true }
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "Packages/Default/Delete Left Right.sublime-macro"}, "context":
[
{ "key": "setting.auto_match_enabled", "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 }
]
},
Notice the escaped dollar signs, \$. In the editor, they show up highlighted in red, and when I try to save the file, I get an invalid escape error message. What is the correct way of escaping the dollar sign?
Mind your escapes
You are going through two layers of programming here. First Python, then JSON. So, your escaped dollar signs actually need to be escaped twice:
"args": {"contents": "\\$$0\\$"}
After Sublime Text reads the settings file, Python will strip the first escape, leaving the following JSON representation
"args": {"contents": "\$$0\$"}
Then, once the JSON is parsed, you will finally end up with
"args": {"contents": "$$0$"}
Don't escape the keystroke
You don't need to escape $ in the keys list. The keystroke is a literal dollar sign, so no escaping is necessary
Here is how the first setting should look:
{ "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", "match_all": true }
]
},