As you know, you can select line under cursor with hot key ctrl + L (linux ubuntu). But selected text include start spaces or tabs and \n at the end.
How can I select line without spaces or tabs?
Save the following sublime-macro to:
Packages/MyMacroFolder/Select LineText.sublime-macro
[
{
"command": "move_to",
"args": { "extend": false, "to": "eol" }
},
{
"command": "move_to",
"args": { "extend": true, "to": "bol" }
}
]
Open your user sublime-keymap file by running Preferences: Key Bindings - User from the command palette.
Add a key-binding for Select LineText.sublime-macro.
{
"keys": [ "ctrl+shift+alt+l" ],
"command": "run_macro_file",
"args": { "file": "res://Packages/MyMacroFolder/Select LineText.sublime-macro" },
},
You will now be able to select line text ( excluding leading & trailing whitespace ) with whatever key-binding you assigned in your sublime-keymap.
The key-binding in the example is Ctrl + Shift + Alt + L
Related
There are many keyboard shortcuts on macOS Monterey 12
https://support.apple.com/en-gb/guide/terminal/trmlshtcts/mac
but some of them are not present in the menu bar so I can not disable them using System Preferences -> Keyboard -> Shortcuts -> App shortcuts
For example for Command + dot (synonyms: cmd+full stop, command-period) is mapped to Break (like Ctrl + c) but I would like to use CMD+. for other things (like open particular window using Automator).
I end up using Karabiner elements.
Start by reading
https://karabiner-elements.pqrs.org
than play with some of the examples
https://ke-complex-modifications.pqrs.org
and at the end you can add custom manipulator that will change CMD+. to CMD+\ inside terminal app.
# .config/karabiner/karabiner.json
{
"conditions": [
{
"bundle_identifiers": [
"^com\\.apple\\.Terminal$"
],
"type": "frontmost_application_if"
}
],
"from": {
"key_code": "period",
"modifiers": {
"mandatory": [
"left_command"
]
}
},
"to": [
{
"key_code": "backslash",
"modifiers": [
"left_command"
]
}
],
"type": "basic"
},
I'm using this two bindings for auto complete:
{
"keys": ["tab"],
"command": "move",
"args": {"by": "lines", "forward": true},
"context":
[
{ "key": "auto_complete_visible", "operator": "equal", "operand": true }
]
},
{
"keys": ["shift+tab"],
"command": "move",
"args": {"by": "lines", "forward": false},
"context":
[
{ "key": "auto_complete_visible", "operator": "equal", "operand": true }
]
},
I would like to add "commit_completion" command to space key:
"keys": ["space"],
"command": "commit_completion",
"context":
[
{ "key": "auto_complete_visible", "operator": "equal", "operand": true }
]
},
But it's not binding, when I press space it acts as normal space(it makes space xD). I'm able to bind it to any other key but not space. What am I missing?
There's not a key code for the space bar that you can bind like that; if you want to bind something to space, you need to use a literal space character:
{
"keys": [" "],
"command": "commit_completion",
"context": [
{ "key": "auto_complete_visible", "operator": "equal", "operand": true }
]
},
This is visible in the Sublime console by using sublime.log_input(True) to turn on input logging and then pressing the key; the only thing that gets logged is a character event, and not a key event.
It's also important to note that you never want to bind anything to a character like this unless you're using a context to constrain when the binding applies, or you lose the ability to type that character.
When I'm typing and I get autocomplete appear eg/if I type ret I get a list of values to choose from:
Is there a way I can get Sublime to choose one of the items by pressing the spacebar rather than having to type tab?
Bad idea isn't it?
Imagine you want to write somthing like ret abc for example. This wouldn't be possible because at the moment you press the spacebar it would select the first item from the auto complete list, in this case returns.
This would make it really cumbersome to write code, so this is not possible.
But it is possible to assign another shortcut to choose an item.
Example for alt+space
insert into user keybinding.
{ "keys": ["alt+space"], "command": "commit_completion", "context":
[
{ "key": "auto_complete_visible" },
{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
]
},
//Edit:
For space ONLY the keys argument is NOT space but a literally space " ". Don't know if this is a feature or a bug but this is the solution to the original question.
{ "keys": [" "], "command": "commit_completion", "context":
[
{ "key": "auto_complete_visible" },
{ "key": "setting.auto_complete_commit_on_tab", "operand": false }
]
},
I have no idea when I try to exit multiple selection state in sublme text with keyboard.
I don't want to use the mouse.
I found a way to fix it.
Firstly, try to read the doc:https://www.sublimetext.com/docs/2/multiple_selection_with_the_keyboard.html
secondly, Maybe the editor become command mode when you useing Esc try to exit the multiple selection state. Opening Setting-User and adding "ignored_packages":["Vintage"].It will be ok.
Even as of Sublime Text 3.2.1 exiting multi-line mode is difficult by default. Instead of switching to vintage mode, you may also bind a new key to exit multi-line mode, which I find a better solution as escape has other functions already that can conflict.
The relevant (default) keybindings are:
{ "keys": ["ctrl+shift+l"], "command": "split_selection_into_lines" },
{ "keys": ["escape"], "command": "single_selection", "context":
[
{ "key": "num_selections", "operator": "not_equal", "operand": 1 }
]
}
In my case I added
{ "keys": ["ctrl+shift+;"], "command": "single_selection", "context":
[
{ "key": "num_selections", "operator": "not_equal", "operand": 1 }
]
}
to my user bindings, but you may choose any key combination you prefer.
In Sublime Text 3, I am trying to alternate a setting's value using the same shortcut, but with differing contexts. Basically, I want to alternate the draw_white_space setting between its three possible values: none, selection, and all.
I change the setting easily enough with three separate shortcuts/keymaps. Here is that code (working):
{
"keys": ["ctrl+e", "ctrl+w"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "all",
}
},
{
"keys": ["ctrl+e", "ctrl+q"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "none",
}
},
{
"keys": ["ctrl+e", "ctrl+s"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "selection",
}
}
But, what I would really like is to be able to press ["ctrl+e", "ctrl+w"] and have it alternate through each possible value. Yes, it is a Visual Studio shortcut that I'm used to!
I created what looks to me like it should work, but it doesn't. At least not how I want it to. Here is that code (broken):
{
"keys": ["ctrl+e", "ctrl+w"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "none",
},
"context": [
{ "key": "setting.draw_white_space",
"operator": "equal", "operand": "all" }
]
},
{
"keys": ["ctrl+e", "ctrl+w"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "selection",
},
"context": [
{ "key": "setting.draw_white_space",
"operator": "equal", "operand": "none" }
]
},
{
"keys": ["ctrl+e", "ctrl+w"],
"command": "set_setting",
"args": {
"setting": "draw_white_space",
"value": "all",
},
"context": [
{ "key": "setting.draw_white_space",
"operator": "equal", "operand": "selection" }
]
}
I have tested out my contexts, so I know they work. For instance, I can manually set all in my settings file, then the shortcut that checks for all will work the first time only. It nor the others will work after that.
Another thing I noticed is that my settings file does not change the draw_white_space value when the shortcut does work (including the three separate shortcuts). I assumed that might be default behavior - the settings changes may be per session - and that would be fine. But, I removed the setting completely and it is still the same behavior.
I am changing the file opened via the Preferences | Key Bindings - User menu, which opened the <Sublime Text>\Data\Packages\User\Default (Windows).sublime-keymap file.
Any ideas? Am I doing something wrong or missing something?
Maybe not what you want, but you can get that behavior with a pretty simple plugin.
import sublime
import sublime_plugin
class CycleDrawWhiteSpaceCommand(sublime_plugin.TextCommand):
def run(self, edit):
view = self.view
white_space_type = view.settings().get("draw_white_space")
if white_space_type == "all":
view.settings().set("draw_white_space", "none")
elif white_space_type == "none":
view.settings().set("draw_white_space", "selection")
else:
view.settings().set("draw_white_space", "all")
After you save the plugin, bind your key binding to cycle_draw_white_space