VS Code jump x lines up/down in any window/menu - keyboard-shortcuts

In VS Code, is there a way to move the cursor x lines up/down in the currently active window or menu? I found a great post showing how it can be done for the text editor window (Microsoft VS Code - Jump 10 lines vertically at once),
{
"key": "ctrl+up",
"command": "cursorMove",
"args": {
"to": "up",
"by": "line",
"value": 10
},
"when": "editorTextFocus"
},
{
"key": "ctrl+down",
"command": "cursorMove",
"args": {
"to": "down",
"by": "line",
"value": 10
},
"when": "editorTextFocus"
},
but I'm trying to get it to work for any window or menu that is currently active, to make navigating with only the keyboard a little faster, such as in the Explorer window (Ctrl + Shift + E), in the Breadcrumb menu (Ctrl + Shift + .) or in the Quick Open menu (Ctrl + P).
Looking at the VS Code keybindings webpage (https://code.visualstudio.com/docs/getstarted/keybindings), under the 'when' clause contexts section it states "If your key binding doesn't have a when clause, the key binding is globally available at all times.", but when removing the when clause from the custom keybinding, it unfortunately still only seems to work in the text editor window, and not in any other window or menu.

Related

How do i select the e.g. first entry in a dropdown list which is created when typing in characters?

I'm testing the chrome extension "Kantu browser automation" and could use some help in figuring out how to select from a drop down list, when the drop down list is created based upon typed characters.
The website I'm testing on is https://uddannelsesstatistik.dk/Pages/dagtilbud_institutioner.aspx
I've tried to record my way through with no success.
I've tried to use click, but can't select the dropdown-list, since it disappears when attempting to clicking on it.
I've tried ClickAt with Coordinates 262,504 and other coordinates as well. Nothing happens.
{
"Name": "Uddannelsesstatistik - Dagtilbud",
"CreationDate": "2019-2-11",
"Commands": [
{
"Command": "open",
"Target": "https://uddannelsesstatistik.dk/Pages/dagtilbud_institutioner.aspx",
"Value": ""
},
{
"Command": "type",
"Target": "id=dawa-autocomplete-input",
"Value": "Aabakken 1, Rebæk, 6000 Kolding"
},
{
"Command": "clickAt",
"Target": "id=dawa-autocomplete-input",
"Value": "262,504"
}
]
}
Right now, it stops when the characters is typed.
The expected output would be that i typed in e.g. "Aabakken 1" and then select the first entry in drop down list "Aabakken 1, Rebæk, 6000 Kolding".
I'm not that experienced in reading html code and how to specify to select first element in a html list, so i could really use all the references, examples, and all help in general.
I have never used kantu before, but you can use the below xpath to identify the first element of the auto completion drop down and you can click on it.
//input[#id='dawa-autocomplete-input']/preceding::label/following::div[1]/ul/li[1]
Give some(at least 3 seconds) delay before performing click action using the above xpath otherwise you will get an error.
I hope it helps...

How to move tabs in Visual Studio Code with the keyboard?

I found the documentation here and here (under moveActiveEditor) for moving tabs, but I have trouble creating a key binding for it.
I created the following (for a Mac, so it uses cmd):
[
{
"key": "alt+cmd+right",
"command": "moveActiveEditor",
"args": {
"to": "position",
"value": i + 1
}
}
]
But when I hit that key command, the tab moves to the first tab position instead of moving one tab position to the right. So clearly, the value of i is 0, meaning it isn't returning the correct value of the current tab.
How can I get this to work?
You need to replace position with right and remove the value attribute:
[
{
"key": "alt+cmd+right",
"command": "moveActiveEditor",
"args": {
"to": "right"
}
}
]

Sublime Text 3: how to bind a shortcut to a specific file extension?

I would like to customize shortcut, but apply them only to a specific extension.
For example,
"jump to matching bracket" -> works in JS files -> customly bound to ctrl+m,
"go to matching tag pair" (emmet) -> works in HTML files -> I would like to ctrl+m also here, but doesn't work (ST3 understand "jump to matching bracket" which doesn't apply here).
I was wondering if specializing a shortcut to a specific extension would do the trick?
Apparently you can try something like this:
[
{ "keys": ["ctrl+x", "ctrl+i"],
"command": "insert_snippet",
"args": {"name": "Packages/User/mysnippet.sublime-snippet"},
"context": [ {"key": "selector", "operator": "equal", "operand": "text.tex.latex"} ]
}
]
Where you'ld replace the first 3 lines by what you want, and text.tex.latex by the scope you want (source.js and text.html.basic in your case).

How to move the cursor to the end of the tag in Sublime Text 2?

When I type the start of a tag, Sublime Text will auto-complete the end of the tag and position the cursor inside the tag.
<code>|</code>
I use | to represent the cursor. So when I finished the contents inside the tag, I want to move the cursor to the end of the tag like this:
<code>blabla</code>|
To do this, now I have to press Right button to move the cursor character by character, which is not efficient. Is there any shortcut to move the cursor to the end of the tag directly?
You could also create a macro. This may be valuable if your tags cover multiple lines. Save the following as something like move_to_end_tag.sublime-macro in Packages/User.
[
{
"args":
{
"to": "tag"
},
"command": "expand_selection"
},
{
"args":
{
"by": "characters",
"forward": true
},
"command": "move"
}
]
You can then create a keybinding for the action.
{
"keys": ["ctrl+shift+alt+right"],
"command": "run_macro_file",
"args": {"file": "res://Packages/User/move_to_end_tag.sublime-macro"}
}
Of course, you can change the keys to whatever you like.
I'm working in Sublime Text 3 rather than 2, but the End button (for me, between the delete and page down) does the trick for me.
I found that annoying as well. Personally, taking the End key binding and applying it to Shift+Space works well enough for my purposes.
If that's easier for you, you can add this line to your user key bindings:
{ "keys": ["shift+space"], "command": "move_to", "args": {"to": "eol", "extend": false} }
Using a macro as skuroda suggested is a good option as well since you end up with more control of the cursor placement.
For curly braces and parentheses you can use Control + M.
Not sure about angle brackets in markup though.

Sublime 3 - Set Key map for function Goto Definition

I want to create an Eclipse style shortcut Ctrl+MouseClick to open the function/method. Sublime Text 3 has already this function called goto_definition but it is bound to F12.
But I'm not sure how to create this binding. I looked here for documentation but it was too complex. Can you one help me out with this simple key binding?
Edit: Following this article I was told to do this: http://webtempest.com/better-definition-navigation-in-sublime-text-3/
[
{
"button": "button1",
"count": 1,
"modifiers": ["super", "shift"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
This doesn't seem to work, ctrl+shift+click executes nothing.
For anyone else who wants to set Eclipse style goto definition, you need to create .sublime-mousemap file in Sublime User folder.
Windows - create Default (Windows).sublime-mousemap in %appdata%\Sublime Text 3\Packages\User
Linux - create Default (Linux).sublime-mousemap in ~/.config/sublime-text-3/Packages/User
Mac - create Default (OSX).sublime-mousemap in ~/Library/Application Support/Sublime Text 3/Packages/User
Now open that file and put the following configuration inside
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
You can change modifiers key as you like.
Since Ctrl-button1 on Windows and Linux is used for multiple selections, adding a second modifier key like Alt might be a good idea if you want to use both features:
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl", "alt"],
"press_command": "drag_select",
"command": "goto_definition"
}
]
Alternatively, you could use the right mouse button (button2) with Ctrl alone, and not interfere with any built-in functions.
To set go to definition to alt + d. From the Menu Preferences > Key Bindings-User. And then add the following JSON.
[
{ "keys": ["alt+d"], "command": "goto_definition" }
]
If you want to see how to do a proper definition go into Sublime Text->Preferences->Key Bindings - Default and search for the command you want to override.
{ "keys": ["f12"], "command": "goto_definition" },
{ "keys": ["super+alt+down"], "command": "goto_definition" }
Those are two that show in my Default.
On Mac I copied the second to override.
in Sublime Text -> Preferences -> Key Bindings - User I added this
/* Beginning of File */
[
{
"keys": ["super+shift+i"], "command": "goto_definition"
}
]
/* End of File */
This binds it to the Command + Shift + 1 combination on mac.
On a mac you have to set keybinding yourself. Simply go to
Sublime --> Preference --> Key Binding - User
and input the following:
{ "keys": ["shift+command+m"], "command": "goto_definition" }
This will enable keybinding of Shift + Command + M to enable goto definition. You can set the keybinding to anything you would like of course.
ctrl != super on windows and linux machines.
If the F12 version of "Goto Definition" produces results of several files, the "ctrl + shift + click" version might not work well. I found that bug when viewing golang project with GoSublime package.
I'm using Sublime portable version (for Windows) and this (placing the mousemap in SublimeText\Packages\User folder) did not work for me.
I had to place the mousemap file in SublimeText\Data\Packages\User folder to get it to work where SublimeText is the installation directory for my portable version. Data\Packages\User is where I found the keymap file as well.
One should not just configure the goto_definition shortcut -- you would also need a shortcut to go back(and forth) after you jump to the definition.
Hence, consider configuring all three shortcuts: goto_definition, jump_back, and jump_forward as follows in your Key Bindings config file :
// go to the definition
{ "keys": ["ctrl+i"], "command": "goto_definition" },
// go back to the previous location
{ "keys": ["ctrl+h"], "command": "jump_back" },
// go to the next location
{ "keys": ["ctrl+l"], "command": "jump_forward" },
I find these three commands especially useful while trying to read code quickly.