Make ctrl+space more like Eclipse - sublimetext2

In the Default (OSX).sublime-keymap file, I see:
{ "keys": ["ctrl+space"], "command": "auto_complete" },
{ "keys": ["ctrl+space"], "command": "replace_completion_with_auto_complete", "context":
[
{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
]
},
But I'd like it to function more like Eclipse, where methods available get popped up after hitting . and waiting for a split second. Is this possible?

Keep in mind that Sublime Text is not an IDE. As such, Eclipse like completion (where it only brings up methods that you can call for the particular variable) is not built in. You may try something like SublimeJava for completions more like Eclipse. I have used it a bit, with mixed results. It did not work as well as Eclipse, but for what I was doing, it was acceptable. To bring up your current set of completions (from within the file by default) when you press ".", you may add the following to your User Preferences (accessible through Preferences -> Settings - User).
"auto_complete_triggers": [{"selector": "source.java", "characters": "."}]
This will cause the auto complete pop up to be displayed when ever you enter . in java files.

Related

How to bind a key for selected text in Sublime Text?

So I have a text for example "this is sample text" and I want it to become this "<![CDATA[this is sample text]]>"
I want to work this function like this: I select any text and use hotkey like ctrl+t or so.
I use Sublime Text 3.
How can I do this for the selection of text?
You can create a new keybinding to use the insert_snippet command to wrap your selection. (Preferences menu -> Keybindings)
{ "keys": ["ctrl+t"], "command": "insert_snippet", "args": {"contents": "<![CDATA[${0:$SELECTION}]]>"}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
]
},

Is it possible to stop tab-autocomplete in Sublime Text 2?

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 },
]
},

Sublime Text 2, Tab Key removes selection on single line (instead of indenting)

(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 }
]
}

sublime in vintage mode - remapping escape failing

I'm trying to mapp jj to escape. I'm getting an error below. Fix?
I think you should place your configuration code in Default (OS).sublime-keymap, not in Preferences.sublime-settings.
You can find it in Sublime Text 2/Preferences/Key Bindings - User menu.
Open Sublime Text Keybindings Settings Default (Windows).sublime-keymap
Go to Preferences -> Key Bindings - User.
Inside your Default (OS).sublime-keymap file, add your remap..
[
{ "keys": ["j", "j"], "command": "exit_insert_mode",
"context":
[
{ "key": "setting.command_mode", "operand": false },
{ "key": "setting.is_widget", "operand": false }
]
}
]

In Sublime Text 2 - reopen build output

In Sublimt Text 2, when I use the build system (make) to run tests, the output is displayed in the build output pane.
However, if I press escape to close the output pane (e.g. to make a fix), I can't find a way to redisplay the output pane to see what else was borked. Have tried to create a custom keybinding to execute show_panel "output", but can't get it working.
Meep?
The menu shortcut is under Tools -> Build Results -> Show Build Results.
I wish this was under the View menu like all the rest of view options...
As you can see in Packages/Default/Main.sublime-menu the command for "Show build results" is this:
{
"command": "show_panel",
"args": {
"panel": "output.exec"
},
"caption": "Show Build Results",
"mnemonic": "S"
},
so a custom key binding could be this:
{
"keys": ["ctrl+alt+super+r"],
"command": "show_panel",
"args": {
"panel": "output.exec"
}
}
And the key binding to hide the panel:
{
"keys": ["ctrl+shift+2"],
"command": "hide_panel",
"args": {
"panel": "output.exec"
}
},
Building on akirk's answer you can make it toggle the build results panel by copying some of the syntax used for the escape shortcuts.
Adding the following lines to the user key bindings will do part of the trick. As reported by some of the previous answers the hide_panel command will hide any panel, and pressing it a second time will reveal build_results.
{
"keys": ["alt+b"], "command": "show_panel", "args": {"panel": "output.exec"},"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": false }
]
},
{
"keys": ["alt+b"], "command": "hide_panel", "args": {"panel": "output.exec"},"context":
[
{ "key": "panel_visible", "operator": "equal", "operand": true }
]
},