It's impossible to unselect my selection by pressing ESC (It keeps the selection I had made)
I want that when I press ESC, that it unselects everything. Is this possible?
This behavior is present in Visual Studio too
VIKASH_DASH's answer is on the right track, but overriding Escape's functionality without context is going to hurt some feelings. Escape is a rather dignified key; take a look at Preferences -> Key Bindings – Default and you'll see that Escape has six important, er, escape-related functions. You definitely wouldn't want to overwrite all of them all of the time!
Thankfully, Sublime Text's keybindings can have contexts. Coupled with some sneaky usage of the move command (have you noticed that hitting Left or Right effectively deselects everything?) you can create a keybinding to add to Preferences -> Key Bindings – User that only executes if you have something selected and doesn't clobber Escape's other functions:
{ "keys": ["escape"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false }
]
}
The "forward": true argument to the move command will move your cursor to the end of the current selection before deselecting (it will also split your cursor if you have multiple selections, just mash it again to escape from that as well!). To move to the beginning instead, change "forward": true} to "forward": false}. Instead of acting almost exactly like Right, Escape is now a glorified Left!
There is a nice deselect package -
it doesn't move the cursor
its in In
preferences->key bindings usr ..
use put these code hope its works;
[
{ "keys": ["escape"], "command": "move_to", "args": {"to": "eof", "extend": false} },
]
Related
I've been using Sublime Text 2 for about 3 weeks, considering it for my new IDE. However, one feature is driving me absolutely crazy.
Autocomplete pops up about 5 times as often as I need it, which would be fine if I could just type away and ignore it. However, it continually inserts whatever it is suggesting when I hit the tab key, and the tab key is used multiple times on each line to format code. This leads to me having to undo autocomplete on almost every line of code I type.
I went into the preferences, which is just a giant text file, and made the following changes:
// When enabled, pressing tab will insert the best matching completion.
// When disabled, tab will only trigger snippets or insert a tab.
// Shift+tab can be used to insert an explicit tab when tab_completion is
// enabled.
"tab_completion": false,
// Enable auto complete to be triggered automatically when typing.
"auto_complete": true,
// The maximum file size where auto complete will be automatically triggered.
"auto_complete_size_limit": 4194304,
// The delay, in ms, before the auto complete window is shown after typing
"auto_complete_delay": 50,
// Controls what scopes auto complete will be triggered in
"auto_complete_selector": "source - comment",
// Additional situations to trigger auto complete
"auto_complete_triggers": [ {"selector": "text.html", "characters": "<"} ],
// By default, auto complete will commit the current completion on enter.
// This setting can be used to make it complete on tab instead.
// Completing on tab is generally a superior option, as it removes
// ambiguity between committing the completion and inserting a newline.
"auto_complete_commit_on_tab": false,
// Controls if auto complete is shown when snippet fields are active.
// Only relevant if auto_complete_commit_on_tab is true.
"auto_complete_with_fields": false,
My reading of the comments is that this should cause autocomplete only to insert its suggestions when I hit enter, which is what I want. However, it continues to do so on a tab. Have I set something incorrectly, or is there a bug in ST2 that prevents the user from turning off autocomplete?
EDIT
To clarify, I'd really like autocomplete to only occur if I press my down arrow to select something in the list and then hit enter. Neither enter nor tab should initiate an autocomplete without me first selecting an item.
I'm using Sublime Text 3 and I add
"tab_completion": false,
into Preferences -> Settings-User and it works.
After dozens of settings permutations, I was able to get Sublime Text 3 to behave how I wanted:
When an autocomplete appears, tab ignores it and enters a tab.
Enter accepts an autocomplete.
Seems like the obvious choice to me.
Preferences > Settings
{
"tab_completion": false,
"auto_complete_commit_on_tab": false
}
Preferences > Key Bindings
[
{ "keys": ["tab"], "command": "insert", "args": {"characters": "\t"}, "context":
[
{ "key": "auto_complete_visible" }
]
}
]
I know it's an old question, but I had the same problem with no answer available. Here is my solution.
Try following settings (works only altogether):
in your user settings add:
// disable auto complete to be triggered automatically when typing.
"auto_complete": false,
// pressing tab calls completion menu, not autocomplete + it still works as ident
"tab_completion": true,
And in the user keymap:
// show autocomplete on tab, not automatically, commit on enter.
{ "keys": ["tab"], "command": "auto_complete", "args": {"default": "\t", "exact": false},
"context":
[
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": ".*[^0-9][^\r ^\n ^\t ^\f]", "match_all": false },
]
},
{ "keys": ["tab"], "command": "auto_complete", "args": {"default": "\t", "exact": false},
"context":
[
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "regex_match", "operand": "[][a-z]", "match_all": false },
]
},
(CTRL + SHIFT + F) it's really a nice shortcut to keep code well organized in eclipse. Is there any thing equivalent for sublime text editor?
Unfortunately there isn't a default key binding equivalent to CTRL + SHIFT + F in eclise. However, there is the reindent command that can be used to make your own key binding.
Open the "Key Bindings - User" from your preferences and add this JSON:
[
{
"keys": ["CTRL+\\"],
"command": "reindent",
"args": {
"single_line": false
},
"context": [{
"key": "selector",
"operator": "not_equal",
"operand": "source.js,source.json,text.html"
}]
}, {
"keys": ["CTRL+\\"],
"command": "htmlprettify",
"context": [{
"key": "selector",
"operator": "equal",
"operand": "text.html"
}]
}, {
"keys": ["CTRL+\\"],
"command": "js_format",
"context": [{
"key": "selector",
"operator": "equal",
"operand": "source.js,source.json"
}]
}
]
This will bind -\ to the reindent command (CTRL + SHIFT + F is already taken by "Find in Files"). single_line is false to force it to reindent the whole page, just like in eclipse.
There are two additional variants of the key bindings for working with HTML and JavaScript. These require that you have the htmlprettify and js_format plugins installed. I found the default formatting inferior for HTML and Javascript, so if you are editing these files I do recommend the plugins. If you don't care about these formats, then you can delete the last two key binding entries.
Go to "preferences/Key Bindings" and add on the right panel this line
{"keys": ["ctrl+shift+f"], "command": "reindent", "args": {"single_line": false}}
that line is meant for indenting all your code in one shot so you would ctrl+a then ctrl+shift+f
Sublime has an build-in feature that does indent lines for you. You can find this when opening the command palette, then look for Indentation: Reindent Lines.
Specific actions to organize your code is harder, because of the different syntaxes of languages.
Luckily enough, Will Bond has been so nice to create a Package Manager for Sublime Text. Using this, features can be added into the editor. These packages do can add code formatting features. You can see a list of formatting packages here.
As one of the tags in your question contains HTML, I'll assume you're looking for a formatting tool for HTML. I've found a package for that, although I've got no personal experience with it. You may install it from here.
A plugin for Sublime Text , that formats (indents) HTML source code. It makes code easier for humans to read.
I would recommend reading through the docs for more information about the package.
you can set shortcut key for one line by press [ctrl+shift+f] easy!!!
goto menu Preferences -> Key Bindings – User
{ "keys": ["ctrl+shift+f"], "command": "reindent"}
see detail at http://how-to-sublime-text.blogspot.com/2014/11/reformat-code.html
(Google turns up this http://www.sublimetext.com/forum/viewtopic.php?f=2&t=14005 but that answer isn't satisfactory to me)
In Sublime Text 2, when you hit tab:
If you have nothing selected it will add a tab (or spaces) at your cursor location. This is good.
If you have multiple lines selected it will indent them all. This is good.
If you have a selection within a single line it will replace this text with a tab. This isn't BAD exactly, but it's not what I want. I'd rather it indents that line, as with multiple lines selected.
I'd think the way to do this would be to create a keyboard shortcut that activates if you have text selected when you hit tab, that "command": "indent"s, but I can't figure out how to say "if you have text selected". The keymap documentation seems to be somewhere between impenetrable and nonexistent....
Does anyone know how to get Sublime Text 2 to do what I want?
It's worth noting that if you select text that doesn't include a newline with multiple cursors it replaces the text with a tab.
With that in mind, putting this in my keymap does what I want:
{ "keys": ["tab"], "command": "indent", "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
}
Thank you ! It works fine. Additionaly, you should want the same principle for unindent (shift+tab) :
{ "keys": ["shift+tab"], "command": "unindent", "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true }
]
}
In Sublime Text we can change key bindings for our needs. But I can't find way to overwrite basic binding for unfold functionality. I have next code in my Key bindings - User file:
{ "keys": ["ctrl+keypad4"], "command": "fold" },
{ "keys": ["ctrl+keypad5]"], "command": "unfold" },
ctrl+keypad4 works as expected, but binding for ctrl+keypad5 not work at all. How to fix it?
I don't want to change global keymap.
You have an extra close bracket in there. It should be:
{ "keys": ["ctrl+keypad5"], "command": "unfold" },
I can't find out how to use upper-case letters as word separators in Sublime Text 2.
What I want is the following behaviour: in some C++ IDE I like, using ctrl+left/right when cursor is in a word like thisIsAComposedWord will move cursor to next upper case in the word (or to the beginning/end of the word).
There's something in Sublime text called "word separators" that seems to do that, it appears his way in the default preferences file:
// Characters that are considered to separate words
"word_separators": "./\\()\"'-:,.;<>~!##$%^&*|+=[]{}`~?",
So can I insert upper-case in that list? Thanks.
You can move by "Subword" with the following Keybinds:
{ "keys": ["alt+left"], "command": "move", "args": {"by": "subwords", "forward": false} },
{ "keys": ["alt+right"], "command": "move", "args": {"by": "subword_ends", "forward": true} },
This recognizes camelCase and under_score.
You can also move by Word with
{ "keys": ["ctrl+left"], "command": "move", "args": {"by": "words", "forward": false} },
{ "keys": ["ctrl+right"], "command": "move", "args": {"by": "word_ends", "forward": true} }
This recognizes "word separators" as specified in your settings file.
I'm using Sublime Text in Linux (Ubuntu) and this works for me:
In your Settings-User add the same content of the "word-separators" by default (which is that you put in the question). Then, to the string add the regular expression of a Upper-Case letter [A-Z]. The result is:
{
"word_separators": "./\\()\"'-:,.;<>~!##$%^&*|+=[]{}`~?[A-Z]"
}
In order to move to the next upper case in a Word, I use Alt + Left/Right arrow.
Edit:
Regular expression doesn't work. The answer is not valid.