Visual Studio Code: How to define key bindings for page-home and page-end - visual-studio-code

Whilst coding I frequently find myself needing to jump either to the top or bottom of a file, but I can't find a quick way to do this with a single key stroke. I tried to define a short cut in the key bindings, but I can't find a function like "page-home" and "page-end". I was going to use the alt key with the home button to jump to the top of a page and alt+end for the bottom.
ie I was expecting to be able to define say:
{ "key": "alt+home", "command": "[what is page home command]", "when":
"terminalFocus"}
So, are there such functions page-home/page-end (I may have this wrong, perhaps its defined as something else).
I've spotted a binding for "cmd+home" bound to "workbench.action.terminal.scrollToTop" which sounds like the right function (and a similar one for "cmd+end"), but they don't work.
UPDATE: I've tried to apply changes to the keybindings via the key bindings page, by defining the keystrokes I mentioned before, and it still does not work. Unless I'm doing something wrong, I . think there is a bug that needs to be reported, unless somebody can say otherwise.
Thanks.

The answer is in this GitHub post. The commands you're looking for are cursorTop and cursorBottom.
Open up the command palette (CTRL + SHIFT + P on Windows) and select Preferences: Open Keyboard Shortcuts File
Add in the following settings in keybindings.json:
{
"key": "ctrl+home",
"command": "cursorTop",
"when": "editorTextFocus"
},
{
"key": "ctrl+end",
"command": "cursorBottom",
"when": "editorTextFocus"
}
replacing the key with whatever shortcut you prefer.

Related

Can VS Code input text when I type a rapid shift shift sequence?

So, my new keyboard doesn't have the pipe key, and I use it frequently (I'm learning elixir right now). I know that alt + 124 produces |, but it is a bit annoying to type it every time I want to use |> on elixir.
Is it possible to configure a shortcut (thought about something like shift shift) to insert |> in the editor?
Microsoft has its own tool to create custom layouts.
Microsoft Keyboard Layout Creator 1.4 Download.
Here is a brief how-to gracefully stolen from MakeUseOf
Open the Microsoft Keyboard Layout Creator app.
Head to File > Load Existing Keyboard.
Pick the layout you want to customize. You should make sure you pick the layout that matches your current keyboard setup, for example, QWERTY (U.S.).
Go to File > Save Source File As so you have a backup before you start making changes.
Set your new keyboard’s parameters in Project > Properties. You can pick a language and give the keyboard a name and description.
Click on a key and follow the on-screen prompt to remap it to a character of your choosing.
Assigning control keys combinations to input letters is not possible, AFAIK. Just set it so Shift+Something or to any 3rd level key. BTW, I am pretty sure your current 3rd level already has a pipe, to test it press the right Alt (also called AltGr) and press all the alphanumeric keys.
{
"key": "shift shift",
"command": "type",
"args": {
"text": "|>"
},
"when": "editorTextFocus"
}
Looks like using two modifier keys in rapid sequence will work soon. Commit merged: see Feature: Shift Shift, Ctrl Ctrl, Alt Alt Keybinds (Double press modifer keybind support)
Will be in v1.54 - works in the Insiders Build now.
You can define a keyboard shortcut
{
"key": "shift+alt+p",
"command": "type",
"args": { "text": "|>" },
"when": "editorTextFocus"
}
You can choose any key combo you like, see the docs

Un-indenting lines in VS Code

Is there an equivalent to editor.actions.indentLines that moves the selected lines to the left instead of to the right?
I know you can use Tab / Shift+Tab for indenting. But unfortunately, that does not work in Vim mode.
That is called "outdenting". See the command:
{
"key": "shift+tab",
"command": "outdent",
"when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus"
}
Just set it to a different keybinding. You can search for "shift tab" in the keybindings to try to figure out what command it is already bound to - in this case "outdent".
EDIT: Actually I see that Ctrl-[ is already bound to outdent so you could try that as well.
No, there isn't. You have editor.action.reindentLines but instead of working as Shift + Tab, it resets the indentation.
There is an open issue (Help Sublime Text users migrate to VS Code) which seems to be mapping this. You could upvote there and maybe comment, asking for the VS Code team to add this command as well.

How to show uses of function in Visual Studio Code?

I am used from Pycharm to be able to press ctrl + click on a function definition and see the uses. Is there an equivalent in VSC?
you can use shift+f12 for get better view of usage
https://github.com/Microsoft/vscode-tips-and-tricks
read this and you can get better idea
2020-03-05 update
You can CTRL+CLICK (Windows) or CMD+CLICK (Mac) on the function name and look on the right column.
Right-click and select "Go to References" or "Find All References" from context menu:
There is, but VSCode doesn't support key bindings with mouse buttons. The relevant issue is #3130. That means that it will not work the same way as it works in PyCharm.
What You can do though is to use - I believe - ShiftF12 or set some key combination to show all usages of function.
To do this You can press CtrlK, then CtrlS and click on 'keybinding.json' link in the sentence: "For advanced customization open and edit keybinding.json".
After getting keybinding.json open, add the following entry there.
{
"key": "ctrl+shift+d",
"command": "editor.action.referenceSearch.trigger",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor"
}
It should let You show usages of function by pressing CtrlShiftD. Obviously, You can customize it however You like.
I also recommend adding the following entry to close the dialog with the same key combination.
{
"key": "ctrl+shift+d",
"command": "closeReferenceSearch",
"when": "referenceSearchVisible && !config.editor.stablePeek"
}

How to assign number keys to sublime text keybinding

I want to create a macro in sublime text using the number key on my keyboard. Is this possible?
My attempts have given me these results:
This works for the number 1 key on the keypad but not on the number 1 key on the keyboad
{"keys": ["alt+keypad1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
This works for the f1 key on the keypad.
{"keys": ["alt+f1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
This does not work!
{"keys": ["alt+1"], "command": "run_macro_file", "args": {"file": "Packages/User/action_self.sublime-macro"}}
It seems like the last mentioned should work. Is there a way to use the numbers of the keyboard to run macros?
Any help will be greatly appreciated!
That should work just fine. For example, under Windows/Linux, that key is bound by default to switch to the first tab in the current tab group:
{ "keys": ["alt+1"], "command": "select_by_index", "args": { "index": 0 } },
Possible problems with this include your operating system/window manager seeing the key and handling it before it gets to sublime or having a keyboard layout that makes that key not map to what you think it does.
To check both, open the Sublime console (View > Show Console from the menu or press Ctrl+`) and enter the command:
sublime.log_input (True)
This will make sublime output to the console whenever you press a key. Press Alt+1 and see what it displays in the console.
If nothing displays, something global is eating the key before Sublime gets to see it, which might be a shortcut in your OS of some sort.
Otherwise, it will display what key it thinks you pressed. If it shows you alt+1, then it's seeing the key and your key binding is just not taking effect for some other reason (wrong filename, the command does not do what you think it does, etc) which is a different issue.
If it shows you a key but not what you expect it to be, that's a result of your keyboard layout. In this case you can either switch to a different keyboard layout or just bind with the key as Sublime is reporting it.
Once you're done, you should run sublime.log_input (False) in the console to turn off input logging (or restart Sublime).

Character "[" (altgr+F) not appearing in the client?

So, after downloading and trying out Visual Studio Code, one issue was critical to me:
I could not do "[]".
The "]" part appears correctly, the "[" however, does not.
The command for "[" is AltGr+F.
I have tried tinkering with the keyboard shortcuts, but this is not a shortcut. The only shortcut that causes similar issues with other IDEs is when Alt+Ctrl+F is mapped and you have a Hungarian keyboard that somehow makes these overlap. However, I see no option of completely removing shortcuts, only adding new ones. Setting this particular shortcut to "" does not help either.
Any way to fix this?
Try to remap action.format to some other key, and "disable" ctrl+alt+f key.
On non-english keyboards: Ctrl+Alt ≈ AltGr.
Add something like this to your keybindings.json:
{
"key": "shift+alt+f",
"command": "editor.action.format",
"when": "editorTextFocus"
},
{
"key": "ctrl+alt+f"
}