sublime text 2 reindent single-line true vs false - sublimetext2

I'm new to sublime text 2, and would like to figure out how to reindent my code properly.
There's certainly the menu item: Edit->Line->Reindent, but I would like to have a keyboard shortcut.
I read this thread: Sublime Text 2: Auto fix indentation for javascript?
Helpful, so I've setup the following two shortcuts:
[
{ "keys": ["f5"], "command": "reindent", "args": {"single_line": false} },
{ "keys": ["tab"], "command": "reindent", "args": {"single_line": true} }
]
I'm trying to sort out the difference between single_line:true and single_line:false. At first, it seemed that single_line:false simply reindents the entire file. But upon closer inspection, it seems to reindent differently.
Take this single line example of javascript code:
var app = angular.module('indexApp', ['chart.js', 'ui.toggle']);
Hitting F5 (single-line:false) keeps the line at the left margin (which seems correct to me)
Hitting TAB (single_line:true) indents the line by one
Hitting F5 toggles it back to the left margin.
So, what's the single_line:true/false really mean ?

Hmmm, it looks like 'single_line' is not my issue here.
Looks like this is my issue: https://github.com/SublimeTextIssues/Core/issues/1271
There seems to be a feature that is causing Javascript (and other) comments to not be indented "correctly". (at least according to my definition of correct).
The fix in the linked issue above works for me... (though I'm guessing I'll lose the fix if I ever update ST) ?

Related

Override language settings

I found out this particular file which can defined behavior of brackets, etc, in a specific language:
https://code.visualstudio.com/api/language-extensions/language-configuration-guide
I would like to simply configure the addition of '$' before and after selected text in LaTeX documents, using for example 'alt+$' keybinding.
So far, it's not clear to me how to do that, even with the documentation pages I stumbled upon.
(https://code.visualstudio.com/api/references/contribution-points#contributeslanguages for example).
I would think that you could simply do that in keybindings.json but it appears you can't (or I don't know how).
Any idea?
If I understand correctly try this snippet:
{
"key": "shift+alt+4",
"command": "editor.action.insertSnippet",
"args": {
"snippet": "$${TM_SELECTED_TEXT}$"
},
"editorLangId == latex"
},
For where to put that snippet see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_create-your-own-snippets
It doesn't seem you can use alt+$ directly but shift+alt+4 is the same thing.

Insert custom characters and move mouse pointer to certain position

I face some issue when trying to add custom key-blinding under Sublime Text 3.
Go under Under Preferences->Key Binding- Users.
Add { "keys": ["alt+k"], "command": "insert", "args": {"characters": "d();"}}
When i Press Alt+k will return me this d(); <-Mouse Pointer end after the semicolon
What i wish to achieve is something like d(Pointer); after press Alt+k <-Mouse Pointer within the braces.
I try figure out some key-Binding Style in the default one but cant find any useful.
PS:I know "command": "move" able to move pointer position but how to combine this with insert,Thanks.
You can archive this behavior without chaining commands with a snippet. Just use this keybinding:
{
"keys": ["alt+k"],
"command": "insert_snippet", "args": {
"contents": "d($0);"
}
},
Where $0 defines the cursor position. You can even use ${0:$SELECTION} to optionally surround the selected text.
To address your PS: If you are interested in chaining commands, then the Chain of Command package could be interesting for you.

sublime text 3 code folder short cut key definition is not working

I am trying to use code folding command, but the short-cut is not working. I have to use menu, which is not convenient.
What does the "," mean in short cut? I tried the short cut on both side of the ",". They all not working. command + K is not working.
I think the reason is there is conflict here:
Then I try to configure a unique short cut key, which is also not woriking. Here is my configure
[
{"keys":["super+;"],"command": "run_macro_file", "args": {"file":"Packages/User/Semicolon.sublime-macro"}},
{ "keys": ["ctrl+enter"], "command": "open_in_browser"},
{ "keys": ["alt+d"], "command": "goto_definition" },
{ "keys": ["command+9"], "command": "fold_level_9" } // here is the definition
]
Can you please tell me what I did wrong?
How do I make the code folding short-cut work?
Thank you!
⌘K, ⌘3 means you hit ⌘K, release both buttons, then hit ⌘3. Sublime allows these compound keyboard commands, and recognizes it as different from ⌘3 alone. Try removing your custom shortcut keys (as they may be interfering with other commands) and seeing if the built-in commands work now.

Bind command show_at_center to space bar in Sublime Text 2

In vim, in command mode, I'm quite fond of using the space bar to center the current line on screen. nmap <space> zz maps this functionality to the space bar in my gvimrc file. I'm trying to bind the same functionality to the space bar in Sublime Text 2:
{ "keys": ["space"], "command": "show_at_center", "args": {"command_mode": true} }
The line above doesn't work. Can anyone tell me why, and what will? I have Sublime's Vintage mode enabled. Also, I have “scroll_past_end”: true in my Sublime Text 2 User Preference Settings so that even the last lines of a file can be centered.
Try adding the following to Packages/User/Vintage/Default (<your OS>).sublime-keymap:
{ "keys": ["space"], "command": "show_at_center",
"context":
[
{ "key": "setting.command_mode"}
]
}
I can't test it right now, but it should work :)
EDIT - it doesn't. See below...
UPDATE
So I've searched far and wide, and it seems that, for whatever reason, you cannot assign an action to space on its own. Assigning it to Altspace works just fine:
{ "keys": ["alt+space"], "command" : "center_on_cursor",
"context": [{"key": "setting.command_mode"}] }
as does assigning it to a function key (F7, for example), or even to a single letter, like M. However, space on its own only results in the cursor moving one character forward when in command mode. The good news is that hitting z,z (lowercase) whilst in command mode will do what you originally wanted to do, which is center the cursor (as does CtrlL, as you indicated). Unfortunately, it is not possible to remap this action onto the spacebar on its own. The programmed action of space in command mode,
set_motion {"clip_to_line": true, "motion": "vi_move_by_characters", "motion_args": {"extend": true, "forward": true, "visual": false}}
just seems to be hard-programmed in. Sorry.

How to use sidebar with the keyboard in Sublime Text 2 and 3?

When using Sublime Text 2 we tend to open the side bar to navigate thru files/folders in our projects. For that we can use the hotkey ctrl+k ctrl+b (in windows).
However, once we're in the side bar, we can't use it with keyboard (arrows for instance). We have to stick using it with our own mouse...
Just a note: I installed SideBarEnhancements plugin, but I didn't find anything that could solve my problem.
Any solution you might know?
You can type Ctrl+0 (Ctrl+Zero) to focus on the side bar.
Then you'll be able to move selection among files with arrow keys and to open the selected file hitting Enter, without touching the mouse.
Another useful shortcut: ctrl + k Together with ctrl + b will show/hide the sidebar. Make sure you hit K and B in the right order
I didn't find any other complete answers, so I pulled together information from various answers and added a bit of my own.
Ctrl+K, Ctrl+B: toggle the sidebar
Ctrl+K+B: shorted form of the above (make sure you hit K and B in the right order)
Ctrl+0: switch focus to the sidebar (if open)
Up/Down: navigate file list
Right: expand a directory
Left: collapse a directory/navigate to parent directory
Enter: open a file
#Santiago Agüero The part you were missing was that the sidebar needs focus before the arrow keys will work (Ctrl+0).
As far as I can know, these shortcuts all work in Sublime 3, as well as Sublime 2.
One caveat: these assume you are using the default keybindings. But you can easily customize the keybindings by opening Preferences > Key Bindings - User and copying over lines from Preferences > Key Bindings - Default, changing the keys value as needed. E.g.,
{ "keys": ["ctrl+k", "ctrl+b"], "command": "toggle_side_bar" },
{ "keys": ["ctrl+0"], "command": "focus_side_bar" },
P.S. To get the fancy-looking keyboard glyphs, use the <kbd> HTML tag. E.g., <kbd>Key</kbd> will turn into Key. (Thanks to https://meta.stackexchange.com/questions/5527) :)
Summary
Ctrl + 0 will navigate to your sidebar. By default you can navigate the folders with your arrow keys. If you prefer 'Vim' type settings, you can avoid using the arrow keys by remapping your keys to the typical Vim settings (hjkl).
h will minimize/open a folder
j will navigate down (i.e. down arrow)
k will navigate up (i.e. up arrow)
l will open up a folder
Enter will open the file
Key mappings
To set this up, open Preferences > Key Bindings - User and add the following:
{ "keys": ["h"], "command": "move", "args": {"by": "characters", "forward": false}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["j"], "command": "move", "args": {"by": "lines", "forward": true}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["k"], "command": "move", "args": {"by": "lines", "forward": false}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] },
{ "keys": ["l"], "command": "move", "args": {"by": "characters", "forward": true}, "context":
[ {"key": "control", "operand": "sidebar_tree"} ] }
Ctrl+p is also really useful for opening files without using the mouse.
If you open a folder in Sublime all the files in that folder (and files in contained folders) will show up in the search you get with Ctrl+p.
Just hit Ctrl+p and start typing parts of the filename and you'll get a list of matches.
For sublime text 3 use Ctrl+K+B
Press and hold Ctrl then press and holdK and then press B
For Sublime Text 2 (and also Sublime Text 3) on Windows use Ctrl+0 to focus on the side bar, and use Ctrl+1 or Esc key to focus on the editor. And if it didn't work, use those 0 and 1 keys that exist in the numeric keys row under the function keys row rather than those 0 and 1 keys that exist in the numeric keypad of the keyboard. This image may demonstrate better: http://en.wikipedia.org/wiki/File:Qwerty.svg
In Sublime Text2, press keys in following format "Ctrl+k+b" and it will work on ubuntu.
It worked on my machine (v14.04 LTS)
I actually had the same issue, the fact that I had to trigger the reveal in side bar and then move focus to the sidebar, alongside with the fact that if the file's folder was already unfolded the focus would move to the sidebar's top, all this made me write a new plugin to reveal the file in sidebar and then move focus to there, making it a lot easier to navigate the sidebar with keyboard arrows, give it a try =)
https://github.com/miguelgraz/FocusFileOnSidebar
Another option is to use the FileBrowser package, which gives you many more actions and can be modified to your needs.
https://packagecontrol.io/packages/FileBrowser
Ctrl + 0 will focus on the side bar.
Ctrl + 1 will focus on the editor in the 1st window.
Ctrl + 2 will focus on the editor in the 2nd window etc.
Sandeep made a great post about improving the keyboard shortcut toggling side bar on/off.Go to Preference->Key Binding and enter:
[
{ "keys": ["ctrl+\\"], "command": "toggle_side_bar" },
]
save it and then press "ctrl+\" to toggle the sidebar.
In Linux new keybindings are saved in ~/.config/sublime-text-3/Packages/User/'Default (Linux).sublime-keymap'.
You have to add a folder to the Sublime Text window in order to navigate via the sidebar. Go to File -> Open Folder... and select the highest directory you want to be able to navigate.
enter this shortcode on Preference->Key Binding
[
{ "keys": ["ctrl+\\"], "command": "toggle_side_bar" },
]
now save it press
"ctrl+\\" for toggle the sidebar