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"
}
Related
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.
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.
I can view side-by-side comparison to current and previous file version in VS Code Source Control/Git View. Are there any hotkey's to navigate on my changes i.e. go to next/prev changes from the keyboard just as if I clicked the Next Change button?
Unfortunately I haven't found anything about it in the key binding documentation page
To go to the next difference use Alt + F5.
To go to the previous difference use Shift + Alt + F5.
You are looking for workbench.action.compareEditor.nextChange/previousChange.
I have it bound to ctrl + down like this:
{
"key": "ctrl+down",
"command": "workbench.action.compareEditor.nextChange",
"when": "textCompareEditorVisible"
}
If anyone here for Visual Studio 2019:
You will go on changes directly in file (In Visual Studio 2019).
Next Change in current file:
You can simply press F8 Key for go to Next Change.
Previous Change in current file:
You can simply press Shift + F8 Key for go to Previous Change.
"when": "textCompareEditorVisible" works perfectly in most cases. But when there is any conflict on the keybinding, && isInDiffEditor is a way, which makes the keybinding work only in diff editor.
{
"key": "cmd+up",
"command": "workbench.action.compareEditor.previousChange",
"when": "textCompareEditorVisible && isInDiffEditor"
},
{
"key": "cmd+down",
"command": "workbench.action.compareEditor.nextChange",
"when": "textCompareEditorVisible && isInDiffEditor"
}
In my case, my keybindings in integrated terminal will be broken if I don't append the condition
The default on OSX/mac is alt + F5 for next and alt + shift + F5 for previous.
Note:
Make sure you have deactivated your fn keys on mac, so you can fully use VS-Codes shortcuts.
In vscode when I mouse hover on let's say, a method call or property it will display some information. I can trigger same thing with keyboard shortcut CMD+H (on mac).
Now with the mouse when I hover while holding the CMD key it will display more information. How to trigger this (CMD+mouse hover) equivalent with keyboard ?
(I'm aware of ALT+F12, but it's not exactly the same trigger.)
Per official docs, the binding for 'Show Hover' is:
⌘K ⌘I
Remember that ⌘K is a 'chord', so do that first (Code will show "⌘K was pressed. Waiting for second key of chord..."), and then ⌘I.
Hope this helps. It's not the most elegant of bindings, but nothing to stop you changing it!
Note:-
For VSCodeVim users, this is: gh.
For Windows users, this is: Ctrl + K Ctrl + I
This answer elaborates on Jack's helpful answer by pointing out the command palette command and how to override its shortcut.
Open the command palette and type "show hover" to find the command.
The default shortcut does not work for me, so I added an override of Ctrl + Space + H.
To add your own override, open the command palette and type "keyboard shortcuts". That opens the shortcut editor. This is how mine looks.
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+space ctrl+h",
"command": "editor.action.showHover",
"when": "editorTextFocus"
}
]
There's a pull request to add this functionality, but it hasn't landed yet:
https://github.com/Microsoft/vscode/pull/59260
I think you are looking for keyboard shortcut for 'Definition Preview'.
command name: Show Definition Preview Hover
command:
editor.action.showDefinitionPreviewHover
To set a keyboard shortcut:
Open keyboard shortcuts
Search for Show Definition Preview Hover
Set your preferred shortcut
Add editorTextFocus to when expression
Or you can append this to your keybindings.json:
{
"key": "ctrl+alt+;",
"command": "editor.action.showDefinitionPreviewHover",
"when": "editorTextFocus"
}
Here ctrl+alt+; is shortcut key I have selected. You add your own.
Usefull reference:
https://code.visualstudio.com/updates/v1_40#_definition-preview-hover-from-the-keyboard
If you're using VSCodeVim, you can add this to your settings.json
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["g", "H"],
"commands": [
{
"command": "editor.action.showDefinitionPreviewHover"
}
]
}
]
By default if you enter gh it will open in hover state.
I have it configured so that if I press gH it shows me the advanced info.
Can I make a multi-line selection of text all capitals in Visual Studio Code?
In full Visual Studio it's CTRL+SHIFT+U to do this.
The extension that exists that I have seen only do non-multi-line blocks.
NOTE: THE UI OF VISUAL STUDIO CODE WHEN THIS QUESTION WAS ASKED (5 OR MORE YEARS AGO) HAS CHANGED.
The question is about how to make CTRL+SHIFT+U work in Visual Studio Code. Here is how to do it in version 1.57.1 or above.
Steps:
Open Visual Studio Code.
Press CTRL+SHIFT+P.
Type
open keyboard shortcuts
Select
Open keyboard shortcuts (json)
An editor will appear with keybindings.json file.
Place the following JSON in there and save:
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
}
]
Now CTRL+SHIFT+U will capitalise selected text, even if multi line. In the same way, CTRL+SHIFT+L will make selected text lowercase.
These commands are built into VS Code and no extensions are required to make them work.
Update August 2021
There is a UI to see and update keyboard shortcuts:
File-> Preferences -> Keyboard Shortcuts.
Find "Transform to Uppercase":
Click the + icon.
In the popup, press the desired key combination and hit enter:
Do the same for lower case.
Note
In the new versions (eg 1.57.x) of VS Code, Ctrl+Shift+L is a shortcut for bulk selecting all selected text occurrences. So you can use another combination, like Ctrl+Shift+/ etc.
Whenever you want to do something in VS Code and don't know how, it's a good idea to bring up the command palette with CTRL+SHIFT+P (CMD+SHIFT+P on mac), and try typing in a keyword for you want. Oftentimes the command will show up there so you don't have to go searching the net for how to do something.
Highlight the text you want to uppercase. Then hit CTRL+SHIFT+P to bring up the command palette. Then start typing the word "uppercase", and you'll see the Transform to Uppercase command. Click that and it will make your text uppercase.
Creator of the change-case extension here. I've updated the extension to support spanning lines.
To map the upper case command to a keybinding (e.g. CTRL+T+U), click File -> Preferences -> Keyboard shortcuts, and insert the following into the json config:
{
"key": "ctrl+t ctrl+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
}
EDIT:
With the November 2016 (release notes) update of VSCode, there is built-in support for converting to upper case and lower case via the commands editor.action.transformToUppercase and editor.action.transformToLowercase. These don't have default keybindings. They also work with multi-line blocks.
The change-case extension is still useful for other text transformations, e.g. camelCase, PascalCase, snake_case, kebab-case, etc.
Update on March 8, 2018 with Visual Studio Code 1.20.1 (mac)
It has been simplified quite a lot lately.
Very easy and straight forward now.
From "Code" -> "Preferences" -> "Keyboard shortcuts"
From the search box just search for "editor.action.transformTo",
You will see the screen like:
Click the "plus" sign at the left of each item,
it will prompt dialog for your to [press] you desired key-bindings,
after it showing that on the screen, just hit [Enter] to save.
In Linux and Mac there are not default shortcuts, so try to set your custom shortcut and be careful about don't choose a hotkey used (For example,
CTRL+U is taken for uncomment)
File-> Preferences -> Keyboard Shortcuts.
Type 'transfrom' in the search input to find transform shortcuts.
Edit your key combination.
In my case I have CTRL+U CTRL+U for transform to uppercase and CTRL+L CTRL+L for transform to lowercase
Just in case, for Mac instead of CTRL I used ⌘
Change letter case in Visual Studio Code
Updated answer
Show All Commands: Ctrl+Shift+P
and start typing "upper" or "lower" whichever command is highlighted, press Enter:
Note 1. The next time you use the function, it is usually enough to type the first letter of "upper" or "lower" words.
Note 2. You can also assign your own shortcut to these functions as they currently don't have any by default:
Original answer from 2017 (no longer valid for newer VSC versions)
To upper case: Ctrl+K, Ctrl+U
and to lower case: Ctrl+K, Ctrl+L.
Mnemonics:
K like the Keyboard
U like the Upper case
L like the Lower case
I think you can use
Select text
Ctrl+Shift+P
Enter Transform to Uppercase
Without defining keyboard shortcuts
Select the text you want capitalized
Open View->Command Palette (or Shift+Command+P)
Start typing "Transform to uppercase" and select that option
Voila!
At Sep 19 2018, these lines worked for me:
File-> Preferences -> Keyboard Shortcuts.
An editor will appear with keybindings.json file. Place the following JSON in there and save.
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorTextFocus"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorTextFocus"
},
]
I'm using the change-case extension and it works fine.
I defined the shortcuts:
{
"key": "ctrl+shift+u",
"command": "extension.changeCase.upper",
"when": "editorTextFocus"
},
{
"key": "ctrl+u",
"command": "extension.changeCase.lower",
"when": "editorTextFocus"
},
Standard keybinding for VS Code on macOS:
Selection to upper case ⌘+K, ⌘+U
and to lower case: ⌘+K, ⌘+L.
All key combinations can be opened with ⌘+K ⌘+S (like Keyboard Settings), where you can also search for specific key combinations.
Select the text to transform.
Use Ctrl + L to selected the whole line
Open Show all commands.
Linux and Windows: Ctrl + Shift + P, Mac: ⇧⌘P
Type in the command, e.g. lower, upper, title
Hit Enter
On a Mac, in Visual Studio Code, its very easy to add a key binding to perform this action, it is not linked to a hotkey combo as a default though.
In the menu bar, navigate to: Code > Preferences > Keyboard Shortcuts
In the search bar that comes up, type: Uppercase
A entry will come up called "Transform to Uppercase"
Hover your mouse over that entry and click the plus sign just to the left of the words "Transform to Uppercase"
In the box that comes up push the keys you want to bind that action to (Cmd +Shift + U is taken so I chose Ctrl + Shift + U) then press enter and you're good to go.
Note this is working at the time of this writing in May of 2021