Sublime Text 2 and Backspace(left_delete) issue - sublimetext2

I am having issue with backspace key binding which is not deleting words in Sublime Text 2 only. In order to back space, either I have to highlight the character(s) that I want to delete and hit backspace or use ctrl + z to go back. And, ctrl + backspace erases the enter word rather than just one character(s). Also, shift + backspace has no effect eventhough it suppose to do the same thing as backspace.
I enabled sublime_log_commands(True) to display the key binding in real time and the log displays the proper binding taking place however it does not deleting any character(s) at all.
backpace => command: left_delete
shift + backspace => command: left_delete
&
Ctrl + backspace => command: delete_word {"forward": false} ( this one I am fine with)
Then, I installed FindKeyConflicts plug-in to see if there was any conflicts but the out put seems fine, IMO.
[shift+backspace]
left_delete Default
.
.
.
[ctrl+shift+backspace]
left_delete Default
run_macro_file Default
.
.
[ctrl+backspace]
delete_word Default
.
.
[backspace]
left_delete Default
run_macro_file Default
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^\"", "match_all": true, "key": "following_text"}, {"operator":
"regex_contains", "operand": "\"$", "match_all": true, "key": "preceding_text"}, {"operator":
"equal", "operand": true, "match_all": true, "key": "selection_empty"}]
run_macro_file Default
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^'", "match_all": true, "key": "following_text"}, {"operator":
"regex_contains", "operand": "'$", "match_all": true, "key": "preceding_text"}, {"operator":
"equal", "operand": true, "match_all": true, "key": "selection_empty"}]
run_macro_file Default
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^\\)", "match_all": true, "key": "following_text"},
{"operator": "regex_contains", "operand": "\\($", "match_all": true, "key": "preceding_text"},
{"operator": "equal", "operand": true, "match_all": true, "key": "selection_empty"}]
run_macro_file Default
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^\\]", "match_all": true, "key": "following_text"}, {"operator":
"regex_contains", "operand": "\\[$", "match_all": true, "key": "preceding_text"}, {"operator":
"equal", "operand": true, "match_all": true, "key": "selection_empty"}]
run_macro_file Default
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^\\}", "match_all": true, "key": "following_text"},
{"operator": "regex_contains", "operand": "\\{$", "match_all": true, "key":
"preceding_text"}, {"operator": "equal", "operand": true, "match_all": true, "key":
"selection_empty"}]
run_macro_file CSS
[{"operator": "equal", "operand": true, "key": "setting.auto_match_enabled"}, {"operator":
"regex_contains", "operand": "^;", "match_all": true, "key": "following_text"}, {"operator":
"regex_contains", "operand": ":$", "match_all": true, "key": "preceding_text"}, {"operator":
"equal", "operand": true, "match_all": true, "key": "selection_empty"}, {"operator":
"equal", "operand": "source.css - meta.selector.css", "match_all": true, "key": "selector"}]
If anyone has any suggestion or work around on how to restore normal backspace operation, I would love to hear it.

Since you said it fixed the issue, I will add it as an answer:
Close all instances, go to your Sublime Text 2 folder and rename to Sublime Text 2 - Backup (for linux, sublime-text-2.backup). So that you don't lose any important stuff. Reopen sublime. This will re-add the aforementioned folder with the default bindings and no extra plugins.
To see what is causing the issue: start adding back the plugins you were using, one by one, and see which breaks backspace. It could also be an issue with conflicting key bindings. So add personal bindings in the same manner as plugins.

I have same problem, look, I searched how to solve this problem, it's this way:
re-install sublime text
with a hex editor software, I use Ghex for Fedora/Ubuntu, run it and menu File->Open, open the sublime text executable (installation folder), then, go to menu: edit->go to byte, and search by 0x590ADC, replace 33 with 32, save it and then execute and paste the license, this is all, backspace key should work.
‎
Tested with Sublime Text 2.0.2 (linux version)

You should 'reset' sublime text 2's settings.
First close sublime text 2 and then open a terminal and type this:
mv ~/.config/sublime-text-2/ ~/.config/sublime-text-2.org
and then restart sublime text 2.
:)

This just happened to me (in SublimeText3), and it turns out I still had the "This is a free copy" alert open in the background. Closing it fixed the issue.

I have this problem on my Kubuntu installation. It's fairy simple:
When you try to crack your sublime, by changing the hex values of
33 42
to
32 42
it will block the simple backspace (left_delete) and del (right_backspace) after 255 characters. (just try it: write 256 characters, and try to delete the last).
Workaround to this problem is to select the desired characters to be deleted, and than do a left_delete/right_delete.
If you want to solve this problem, do as other suggested, that is, to reinstall your sublime (with an unregistered version).
This problem is not found on Windows.

easily go to Preferences -> Key Binding - Default
search for keys aliases and edit whatever u want save it then its good to go

I, too, faced the same problem today, and after searching through the documentation, I found the reason and solution to the problem.
This problem occurs because you may have accidentally changed some settings. So you have to revert those settings.
Now, go to Preferences -> settings -> user settings now check for "ignored_packages": ["Vintage"]
and remove it from user settings.
That's all nows your key shortcuts will work fine.

Related

Sublime Text 3 Reindent with proper array parenthesis in PHP

I Have a problem like that
but answer in link above don't helped me. I get used to reindent whole file while coding and I liked Sublime Text very much. But this bug makes me mad. So I need to reindent whole PHP files with shortcut and don't get wrong indenting.
This is how i need:
And this is how it does:
As #BullfrogBlues mentions in a comment, the Sublime PHP Grammar plugin has a fix for this. I did not want that entire package, but fortunately it is very easy to extract out just the array indentation rule from there:
https://github.com/gerardroche/sublime-php-grammar/blob/master/Indentation%20Rules%20-%20Arrays.tmPreferences
Just save that file into the same directory where all your custom snippets etc. go (on Mac it's ~/Library/Application Support/Sublime Text 3/Packages/User, not sure about Windows/Linux) and voila!
The following solution was taken from SublimeText Forum.
Add this to your keybindings:
{ "keys": ["enter"], "command": "insert_snippet", "args": { "contents": "\n\t$0\n" }, "context":
[
{ "key": "setting.auto_indent", "operator": "equal", "operand": true },
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "punctuation.section.array.end.php", "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "array\\($", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\)", "match_all": true },
]
},
I'm using Sublime Text 3 and could solve this problem using the instructions on that page. I'm copying the same instructions here for reference, and I'll try to give some hints to find out why it isn't working for you.
First I've added those lines in my keybinding settings (Preferences -> Key bindings - User):
{ "keys": ["enter"], "command": "run_macro_file", "args": {"file": "Packages/User/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 }
]
}
You must pay attention here that this settings file is a JSON-Array, and the above code must written in brackets:
[
// Copy above configuration here
]
If there are already some keybindings in your settings file, you must separate them with commas:
[
{
// Some existing keybindings
},
// Copy above configuration here
]
Then you should create a macro file in you user folder for Sublime Text 3. Where to find this folder depends on the operating system you are using. For instance, on Ubuntu it is:
~/.config/sublime-text-3/Packages/User
Create a new file in this folder, and name it (pay attention to cases and spaces):
Add Line in Braces.sublime-macro
In this file, copy the following script and save:
[
{"command": "insert", "args": {"characters": "\n\n"} },
{"command": "left_delete", "args": null},
{"command": "move", "args": {"by": "lines", "forward": false} },
{"command": "move_to", "args": {"to": "hardeol", "extend": false} },
{"command": "reindent", "args": {"single_line": true} }
]
This must be working, it works for me.

Is there a way to change the line ending style in Sublime Text 2?

Is there a setting for this?
Sublime Text to autocompletes braces (curly brackets) using the end-of-the line style. Convention at work is to use beginning-of-the-line (or Allman) style. Is this configurable?
Perhaps not the most optimal way to accomplish this, as this will not be project or language specific, is to edit your ~/Library/Application Support/Sublime Text 2/Packages/User/Default (OSX).sublime-keymap (or the file appropriate to your OS) and add:
{ "keys": ["{"], "command": "insert_snippet", "args": {"contents": "\n{\n\t$0\n}"}, "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 }
]
}
This will result in the following behavior when { is pressed, only when the preceding character is ):

Skip autocompleted brackets, commas etc. with tab in sublime-text

In sublime, if you type, alert("{<cursor> it will autocomplete the closing brackets and quotes to: alert("{<cursor>}").
In visual studio, if you hit tab, it will place the cursor at the end of the autocompleted characters.
How can I replicate this exact behaviour in sublime? I don't see much point in autocompletion if you have to type those characters anyway or use arrow keys.
Building on #AGS's answer and your comment, there are two possible options. The first (if you're not using OS X) is to just hit End, which will move the cursor to the end of the line (eol).
The second option is to slightly modify #AGS's keymap to the following:
{
"keys": ["shift+enter"], "command": "move_to", "args": {"to": "eol", "extend": false}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]\\}\\$]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
}
The binds the eol functionality to ShiftEnter, and includes the regex support, which can be removed if you want.
I hope this helps!
Edit your .sublime-keymap file and add
// Skip past round and square autocomplete brackets
{
"keys": ["shift+enter"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "following_text", "operator": "regex_contains", "operand": "^[)\"\\]\\}\\$]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]
},
In this case, shift + enter will function like tab in visual studio.
The solution is originally not mine - I found it either here or on the ST2 forum.

Custom bracket auto-closing in Sublime Text

I'm trying to auto-close the asterisk (*) character in Markdown files.
I've been looking through all the language setting files, and am turning up nothing to use as an example. I've also tried writing a snippet, but found it inefficient (it doesn't wrap around the selection).
I searched around and found BracketHighlighter (which claims to allow custom auto-close pairings) but with no luck (installed through Package Control, also restarted).
Any ideas on where I should start or what I'm doing wrong?
Solution (thanks to #skuroda)
skuroda's answer will do fine - however, I've made a few tweaks that I would like to append to their answer:
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "$0**"}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\*\\*", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
}
Which adds two ** if the asterisk key is pressed next to two preceding asterisks (e.g. **| then ***| becomes **|** where | is the cursor. This helps a lot with emboldening text.
You may need to tweak the context some, but this should be a start. This is based on the auto pair key bindings for the built in brackets.
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*$0*"}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|;|\\}|$)", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "*${0:$SELECTION}*"}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": false, "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
},
{ "keys": ["*"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[
{ "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^\\*", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.html.markdown", "match_all": true }
]
}
Use this
{ "keys": ["*"], "command": "insert_snippet", "args": {"name": "Packages/User/my-snippet.sublime-snippet" }}
now go to Preference>Browse Packages and then User folder
Create a file
my-snippet.sublime-snippet
and use following code inside
<snippet><content><![CDATA[
*${0:$SELECTION}*
]]></content></snippet>
Good Luck
Here's my version. It's also based on the built-in auto pair key bindings, but with some tweaks.
[
{ "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": "^(?:\\s|\\.|,|:|;|!|\\?|'|\"|‐|-|—|\\)|]|\\}|⟩|>|›|»|$)", "match_all": true },
{ "key": "preceding_text", "operator": "not_regex_contains", "operand": "\\S$", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.plain, text.html.markdown", "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 },
{ "key": "selector", "operator": "equal", "operand": "text.plain, text.html.markdown", "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 },
{ "key": "selector", "operator": "equal", "operand": "text.plain, text.html.markdown", "match_all": true },
]
},
{ "keys": ["backspace"], "command": "run_macro_file", "args": {"file": "res://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 },
{ "key": "selector", "operator": "equal", "operand": "text.plain, text.html.markdown", "match_all": true },
]
},
]
Unlike the default, this version will:
make character pairs only when the caret is preceded by a whitespace character or beginning of a line (e.g. the default doesn't allow auto pairing after o, but does after ö or $ - this version excludes everything)
make pairs when the caret is followed by various characters (., :, !, " and more - the default only allows pairs to be made before a space, tab and some brackets)
only work in plain text Markdown files (.txt and .md)
I use this version for quotation marks too, replacing the default (of course allowing quotation marks globally).
Double characters
My version of double character functionality (similar to OP's/based on the default, but with a tweak):
[
{ "keys": ["*"], "command": "insert_snippet", "args": {"contents": "$0**"}, "context":
[
{ "key": "preceding_text", "operator": "regex_contains", "operand": "\\*\\*", "match_all": true },
{ "key": "following_text", "operator": "not_regex_contains", "operand": "\\*", "match_all": true },
{ "key": "selector", "operator": "equal", "operand": "text.plain, text.html.markdown", "match_all": true },
]
},
]
This will make double characters, in this case asterisks (*), if there are already two consecutive asterisks anywhere in the line preceding the caret.
The tweak allows skipping asterisks (one at a time) when the caret is followed by any asterisk.
OP's version always adds two new asterisks if there are already two consecutive asterisks in the line preceding the caret, even if the caret is followed by an asterisk, which is undesired behaviour (for example just after adding a second double asterisk, pressing the asterisk key would add two more instead of skipping the new asterisks).
Explanations
From Sublime Text's default key bindings:
One rule states that in order to make a pair the caret must be preceded by lowercase letters, uppercase letters, numbers, the same symbol or an underscore:
{ "key": "preceding_text", "operator": ^"not_regex_contains", "operand": "[\"a-zA-Z0-9_]$"^, "match_all": true },
However, it still allow a pair if the caret is preceded by other letters or symbols (ö, ž, đ, ç, 蘋, Ψ, ?, ~, [, •, $, etc.)
It shouldn't do that so I tweaked it.
The following requires the caret to be preceded by a whitespace character or beginning of a line (it excludes all other symbols, not just basic letters and numbers):
"not_regex_contains", "operand": "\\S$"
It's a double negative to include beginnings of lines.
The following would only work after whitespace characters (space, tab, other) but NOT at the beginnings of lines:
"regex_contains", "operand": "\\s$"
Another rule states that in order to make a pair the caret must also be followed by certain characters: tab, space, ), ], }, >, end of line:
{ "key": "following_text", "operator": "regex_contains", "operand": "^(?:\t| |\\)|]|\\}|>|$)", "match_all": true },
I thought that character pairing should also be allowed if other characters follow the caret, namely punctuation marks and other whitespace characters not included in the default.
The following includes more punctuation marks (., ,, :, ;, !, ?, ', ", ‐, -, —, ⟩, ›, ») and all whitespace characters:
"^(?:\\s|\\.|,|:|;|!|\\?|'|\"|‐|-|—|\\)|]|\\}|⟩|>|›|»|$)"
Note that a whitespace character preceding the caret is required, meaning that a pair would not be made when not wanted.
This would help in a situation where one wants to start writing formatted text at the end of a sentence but before the punctuation at the end of that sentence, for example (| represents the caret):
"This is a sentence|"
"This is a sentence |" // user types a space
"This is a sentence *|*" // User types a character and it gets a pair instead of staying single
"This is a sentence *with more words|*"
This question was asked several years ago, but hopefully my answer will be useful to everyone in the future who is interested.

Coding with Sublime Text 2

Simple question, I just started coding with Sublime Text 2 on windows, and I want to change little things, like when I am writing an if statement such as if (i > 0), immediately after I type the "0", my cursor is between the "0" and ")", so if I hit enter, I want it to jump to after the ")". I am used to eclipse so I want to know how I can get the settings to mimic those of eclipse. I have tried editing the settings text files but couldn't find what I was looking for.
Try adding the following to your User key bindings (accessible through Preferences -> Key Bindings - User)
{ "keys": ["enter"], "command": "move", "args": {"by": "characters", "forward": true},
"context": [
{ "key": "selection_empty", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": "[[:space:]]*", "match_all": true },
{ "key": "following_text", "operator": "regex_contains", "operand": "^[\\)]", "match_all": true },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false }
]}
edit: Update regex to only match parentheses.