How do i add a git: link reference in vs code help menu? - visual-studio-code

When i cmd + shift + p i get the following screen in vs code
One of the options i see is keyboard shortcut references, When i click on this link , it opens a tab in the browser which showcases all the keyboard shortcuts.
Now i'd like to add a similar link titled Git: Open Aliases with a link that goes to HERE. How do i do this ?

The functionality of the IOpenerService is in the API as vscode.env.openExternal
You can use the extension HTML Related Links v0.14.1
Use the command htmlRelatedLinks.openURL it works the same as the Ctrl-Link-Click. You get the Trust dialog.
Define a keybinding
{
"key": "ctrl+i ctrl+g",
"command": "htmlRelatedLinks.openURL",
"args": "https://raw.githubusercontent.com/GitAlias/gitalias/master/gitalias.txt"
}
If you want a command in the Command Palette you have to define it in the package.json file of an extension. In this file is the string used to display in the Command Palette.
In this extension I have defined a command to open the GitAlias page and show the command in the Command Palette as: Git: Open Aliases
You can set a key binding for this command.

Related

How to find out which extension provided the command in vscode?

I'm clueless what feature came out of which extension, is there a way to have its source displayed?
Also would be interesteed to know if its possible to trace the source code of the features.
The only thing I can think of is checking the package.json files, as even vscode.commands.getCommands() only returns plain strings. This can be done with the vscode.extensions API:
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
setTimeout(() => {
for (const extension of vscode.extensions.all) {
let commands = extension.packageJSON.contributes?.commands;
if (!Array.isArray(commands)) {
continue;
}
for (const command of commands) {
console.log(command.title + " is from " + extension.id);
}
}
}, 2000);
}
Note that all only includes activated extensions, hence the timeout to make sure all extensions that activate on startup are done with their activation.
what feature came out of which extension
Yes, you can do this, taking advantage of VSC's intellisense:
I'm Assuming (1) by feature, you mean a command executable from the command pallette and
Open keybindings.json in vscode
You should see JSON like below; if not, add one like below (you're not going to keep it).
{
"key": ".",
"command": "REPLACE THIS WITH YOUR COMMAND NAME",
"when": "suggestWidgetVisible"
}
Where it says "REPLACE THIS WITH YOUR COMMAND NAME", begin typing the name of the command you're interested in
The VSC suggestion widget will open, showing roughly EXTENSION_NAME.YOUR_COMMAND. If the suggest widget doesn't open, press ctrl+space to open it.
Note the name of the extension; that's what contributed that feature/command. If the name doesn't match an extension, it's probably a core VSC feature
trace the source code of the features
Most extensions are on GitHub, as is the core code for VSC, so you can simply navigate to the relevant repository and seacrch the code for that command.
Check this link out from VS Code documentation.
Here you can see where the extensions are installed by default.
And further, you can access their source code.
Where are extensions installed?
Extensions are installed in a per user extensions folder. Depending on your platform, the location is in the following folder:
Windows %USERPROFILE%\.vscode\extensions
macOS ~/.vscode/extensions
Linux ~/.vscode/extensions
You can change the location by launching VS Code with the --extensions-dir command-line option
About which feature cames from which extension, I'm not sure if it's possible to achive that.
Click on an extension and in the editor that opens showing its readme, click on the Feature Contributions link and you'll see the settings and commands that extension contributes. For example:

Sublime Merge - keyboard shortcut for "File History"

How can I make a keyboard shortcut for Navigate > File History... in Sublime Merge?
The command for this is file_history; it will prompt you interactively in the command palette and commands of that nature need to be invoked via the show_command_palette command.
So, a key binding that duplicates what the menu item Navigate > File History... does would look like the following (using an example key; change that as desired):
{
"keys": ["ctrl+alt+t"],
"command": "show_command_palette", "args": {"command": "file_history"}
},
This binding goes into the Default (<PLATFORM>).sublime-keymap file in your Merge User package, where <PLATFORM> is one of Linux, Windows or OSX depending on what platform you're using.
You can locate the User package by choosing the Preferences > Browse Packages command from the menu and then navigating inside of the User package.
Note that just like Sublime, the sublime-keymap file is a JSON file that is a list of key bindings; thus if you don't already have key bindings, you need to wrap the key binding above in [ and ] characters to make it the first item in the list.

How can I clear the terminal in Visual Studio Code?

I need to clean the contents of the terminal in Visual Studio Code.
Every time I use Maven, the output of the terminal is attached to the previous build, which is confusing me.
How do I clear the terminal window with some command or keyboard shortcut?
cls doesn't work; it only hides the text.
Use Ctrl+K. This goes clean your console in Visual Studio Code.
Per comments, in later versions of VSCode (1.29 and above) this shortcut is missing / needs to be created manually.
Navigate: File > Preferences > Keyboard Shortcuts
search for workbench.action.terminal.clear
If it has no mapping or you wish to change the mapping, continue; otherwise note & use the existing mapping
Double click on this entry & you'll be prompted for a key binding. Hold CTRL and tap K. Ctrl + K should now be listed. Press enter to save this mapping
Right click the entry and select Change when expression. Type terminalFocus then press enter.
That's it. Now, when the terminal is in focus and you press Ctrl+K you'll get the behaviour you'd have expected to get from running clear/cls.
Ctrl + Shift + P and select Terminal:clear
FOR VERSIONS AT AND ABOVE v1.32 SEE BELOW
Bindings for this command still need to be setup manually, even at v1.33.1, which I am at. The command is there under Terminal: Clear but the binding is blank. Here is how you can setup bindings in v1.32 and up.
Open up the Keyboard Shortcuts with Ctrl+K, Ctrl+S. Then click on the {} next to the Keyboard Shortcuts tab to open up the keybindings.json file.
After doing so, find some open space anywhere in the file, and type in the key bind below.
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
FOR VERSIONS UP TO v1.32 SEE BELOW
This is for Visual Studio Code v1.18 up to v1.32, I believe; I am on v1.29.1. Since apparently there are a whole lot of assumptions about the default bindings, here is how you set up a binding, then use it. Keep in mind this binding will completely delete all of the history in your terminal too.
Open up the Keyboard Shortcuts with Ctrl+K, Ctrl+S. Once you are in Keyboard Shortcuts, click on keybindings.json in the text that says ....open and edit keybindings.json. Then on the RIGHT side, in the keybindings.json, add this (make sure you put a comma before the first { if there are one or more bindings already):
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
FOR ALL VERSIONS
Remember, the "key": can be whatever binding you want. It doesn't HAVE to be Ctrl + K.
To use the keybinding, you must have focus in your terminal, and then do the binding.
To clear Terminal in VS Code simply press Ctrl + Shift + P key together this will open a command palette and type command Terminal: Clear. Also you will go to View in taskbar upper left corner of vs code and open Command pallete.
This will clear the terminal easily & work for any directory you have open in your terminal.
This is for Windows, also try if it works for Mac.
This is command is work in all VS code versions include latest version 1.52.1
Go to
File >Preferences >Keyboard shortcuts.
Search for "Terminal: clear"
By default no keyboard shortcut is assigned.
Just click on the Plus (+)icon in the banner and give the preferred
shortcut of your choice to clear the terminal.
I prefer to use ctrl+k as that shortcut is not assigned with any command.
2019 Update (Read in Full)
Shortcut
Mac: cmd + k
Windows: ctrl + k
TroubleShooting
If the shortcuts do not work for you, the most likely scenario is that either you or an extension you installed has added an open ended ctrl + k / cmd + k chord to another shortcut.
Open ended meaning, the shortcut does not have an explicit when clause that excludes terminal focus. There are two possible solutions here.
Solution 1:
If you added the shortcut, simply go to your keybindings.json file and add a when clause that does not include terminal focus. Example:
{
"key": "cmd+k cmd+c",
"command": "someCommandHere",
"when": "editorTextFocus",
}
Solution 2:
Alternatively, you can add the workbench.action.terminal.clear command to the very bottom of keybindings.json, ensuring it takes precedence over other shortcuts. It'd be wise to add a comment so you don't forget and later place new chords below it. Example:
// Keep this keybinding at very bottom of file to ensure terminal clearing.
{
"key": "cmd+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus",
}
For additional information, check out this GitHub issue.
For a MacBook, it might not be Cmd + K...
There's a long discussion for cases where Cmd + K wouldn't work.
In my case, I made a quick fix with
cmd+K +cmd+ K
Go to menu Preferences -> Key shortcuts -> Search ('clear'). Change it from a single K to a double K...
Use Ctrl+K to clear the terminal.
But this is not possible in Linux Visual Studio Code.
For Linux you can do like below:
Via the command palette: ctrl+shift+p, "tclear"
To add this in shortcuts, copy paste this in keybinding file:
{
"key": "ctrl+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
V1.33 won't accept ctrl + k to clear terminal (Windows).
You need to enable manually by adding below code in your keybiniding.json, it will override the defaults.
In your VSCode, press ctrl + shift + p, search for keyboard and click on Open Keyboard Shortcuts to open the keybindings.json file.
Note: If you open the Default one, it will show the default settings, but as this file is read-only, you can't edit it manually.
Paste the following script in keybindings.json
{
"key": "ctr+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
Save the file.
Now your terminal will clear by crtl + k
To clear the terminal, using default keybindings on the newest version of VS-Code, you press CTRL-L.
You can use below to clear the screen in terminal:
cls;
or
clr
Right click on the terminal and select clear option (for ubuntu).
For mac just type clear
workbench.action.terminal.clear no longer works (at least for VS Code Insiders 1.54 on Mac)
The following is the way to now map CTRL+L yo the default console functionality.
{
"key": "ctrl+l",
"command": "workbench.action.terminal.sendSequence",
"args": {"text": "\u000c"},
"when": "terminalFocus"
}
If you're on a Mac, it's ⌘+k. :)
By default there is NO keybinding associated to clearing the terminal in VSCode. Therefore, one must add a NEW Keybinding by following the below steps:
Navigate: File --> Preferences --> Keyboard Shortcuts. (Or Ctrl + K and Ctrl + S together)
Type in the Search Bar on top: Terminal: Clear.
An entry with Command: Terminal:Clear will show up with the following VSCode command workbench.action.terminal.clear.
Right Click on it and press Change Keybinding. Then press Ctrl + K together and then Enter. It will be saved.
Right Click again and press Change When Expression. Just enter: terminalFocus. It will be saved.
Finally, open your integrated terminal and with focus inside the terminal, press Ctrl + K.
Navigate in VS code: File > Preferences > Keyboard Shortcuts
search for workbench.action.terminal.clear
Double click on this entry & you'll be prompted for key binding. Hold CTRL and tap L. Ctrl + L should now be listed. Press enter to save this mapping
That's it.
The accepted answer should be the following which was unmultimedio's comment to one of the answers above:
Cmd+K will work, you just need to set again in the Keyboard Shortcuts
the workbench.action.terminal.clear to Cmd+K, so it shows as Source:
User instead of Source: Default – unmultimedio Mar 12 '19 at 1:13
Just click the gear button on the left-bottom side on the VS code screen
then Search for "Terminal: clear"
By default no keyboard shortcut is assigned.
Just double click the Terminal: Clear
and give the preferred shortcut of your choice to clear the terminal.
Usually ctrl+k is used as that shortcut is not assigned with any command.
FYI: This method is the same as #SuRa but is a little simpler.
Btw: I use VS Code version 1.43.0
I am using Visual Studio Code 1.52.1 on windows 10 machine.'cls' or 'Clear' doesn't clear the terminal.
just write
exit
It will close the terminal and press
ctrl+shift+`
to open new terminal.
You can change from settings menu (at least from version 1.30.2 and above)...
On Mac, just hit Code > Preferences > Settings.
Then just search for "clear" and check Clear Previous Output.
The Code Runner extension has a setting "Clear previous output", which is what I need 95% of the time.
File > Preferences > Settings > (search for "output") > Code-runner: Clear previous output
The remaining few times I will disable the setting and use the "Clear output" button (top right of the output pane) to selectively clear accumulated output.
This is in Visual Studio Code 1.33.1 with Code Runner 0.9.8.
(Setting the keybinding for Ctrl+k did not work for me, presumably because some extension has defined "chords" beginning with Ctrl-k. But "Clear previous output" was actually a better option for me.)
Select Open Keyboard Shortcuts from command palette and put following to keyboard shortcuts file:
{
"key": "cmd+k",
"command": "workbench.action.terminal.clear",
"when": "terminalFocus"
}
F1 key opens the shortcuts for me using windows 10. Then type Terminal and you see the clear option.
In kde's konsole there is an action called "clear scrollback". It not only clears the terminal as usual, but also deletes the previous lines, so that you cannot scroll back and be confused.
I found in vs codium you can open Settings, search for terminal. Then go to Debugging, Debug - Terminal - Clear Before Reusing.
Set checkbox there, and every time you start a new debugging, the terminal scrollback history will not bother you.
To permanently delete the previous commands, use this
Set-PSReadlineOption -HistoryNoDuplicates
Remove-Item (Get-PSReadlineOption).HistorySavePath
Alt-f7
paste this command -
Remove-Item (Get-PSReadlineOption).HistorySavePath
in your powershell and start new powershell and its found cleared
for further details check this link # https://www.shellhacks.com/clear-history-powershell/
I'm running the June 2020 update of Visual Studio Code. I was looking for a simple way to clear the history of Terminal output from a Python script. Killing the Terminal via clicking on the trash can icon on the upper right did what I needed, and my Conda environment automatically reactivated.
Try typing in 'cls', if that doesn't work, type 'Clear' capital C. No quotes for any. Hope this helps.
I am using Visual Studio Code 1.38.1 on windows 10 machine.
Tried the below steps:
exit()
PS C:\Users\username> Cls
PS C:\Users\username>python
just type 'clear' in the terminal (windows)
or ctrl+shift+p and
on mac - right click

Is there any command to open list of branches in VS Code?

There is a command git.branch in VS Code keyboards shortcuts. This command opens dialog to create new branch.
I can not find the command to open list of all branches. Is there any command for it?
Yes, there is the git: Checkout to... command. It displays the picker including all known branches.
You can execute this command also by clicking on the current branch name displayed on the statusbar's left side.
Look for the command git.checkout in case you want to create a keybinding for it.
If you add the following code to your keybindings.json then you will trigger the command by typing SHIFT+ALT+G:
{
"key": "shift+alt+g",
"command": "git.checkout"
}
You can also import you keybindings from webstorm by doing following way:
Code > Prefrences > Migrate shortcuts from ... and then install IntelliJ IDEA keybindings from Keisuke Kato

How to add multiple terminals in VS Code?

Can we add multiple different terminals in the VS Code? I am planning to add following three terminal and work with all of those :
Windows Command prompt
PowerShell
Git Bash
I know I need to add the following command in Preferences => Setting
// // 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
// // 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
// // Git Bash
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
I want to add all of the above three commands in setting.json
And when I click + different terminal should open and I want to work with those terminals without changing the preferences.
Is it possible in VS Code or not?
There is a way to make this happens with these steps by installing an extension:
Find an extension called Shell launcher and install it or you can find it here. Reload VS Code if you want or after you finished all steps.
Go to Files --> Preferences --> Settings and this will open settings.json file and you then insert this (you can edit this to your heart's content):
Code:
"shellLauncher.shells.windows": [
{
"shell": "C:\\Windows\\<sysnative>\\cmd.exe",
"label": "cmd"
},
{
"shell": "C:\\Windows\\<sysnative>\\WindowsPowerShell\\v1.0\\powershell.exe",
"label": "PowerShell"
},
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"label": "Git bash"
},
{
"shell": "C:\\Windows\\<sysnative>\\bash.exe",
"label": "WSL Bash"
}
]
PS: You can use shellLauncher.shells.linux for Linux or shellLauncher.shells.osx for macOS.
Go to Files --> Preferences --> Keyboard Shortcuts and then find on {} icon on the top right corner to open keybindings.json file. Insert this:
Code:
[
{ "key": "ctrl+alt+`", "command": "shellLauncher.launch" }
]
Update: Type shelllauncher into the search bar. You can then see Shell Launcher: Launch command. Highlight and use any keybinding you like. For example, I picked Ctrl + Alt + (backtick)` for myself.
You can reload your VS Code and click the key combination you have assigned and that will give you the option to choose which integrated terminal you want to use.
For more details, please check the official site: https://marketplace.visualstudio.com/items?itemName=Tyriar.shell-launcher
Enjoy!
Even the question is asked last year and the answer is accepted but still I feel to answer this question as I didn't found any simple, suitable and complete answer while as a development I need multiple terminal handy in a click like below:-
and I don't bother about their path, add another extension for what the VS Code is already capable of or reload VS Shell etc and go to insert and setup the settings files manually.
I found this question is asked many times and almost all landed up manually setup of write some settings etc. or sometimes only opted to get a single type of terminal. The answer of #Pawan is somewhat near but again that solution finally land up to a single terminal, going to command setup for switch terminal and this one will work for git or any other terminal.
If you have tools installed which worked on command line like power-shell and git along with default cmd prompt in windows then the follow the quick three steps to get all terminals at once and switch to anyone with a click.
Open terminal, it should be visible (use ctrl+` or from menu View-> Integrated Terminal )
Open commands search (use Ctrl+Shift+P or from menu View->Command Palette...)
In command box Type "Terminal: Select Default Shell" to select this option from drop down.
As you select this option, then all the available commands which are in path will be listed below like below
Just click any one which you like to add for quick access from command list.
Finally, in the terminal window, just click on + sign next to terminal list as shown below:-
The terminal selected in step 5 will now added after performing step6 to the list without removal of earlier terminal.
Repeat step 3-6 for adding any other terminal to command list.
To work with particular terminal just select the required one in the terminal list of the terminal window.
press ctrl + shift + ` shortcut, or press a cross sign to run new terminal, then type bash if your default mode is powershell or powershell if your default mode is bash. And here you are, your terminal is switched.
For now VS Code support defining only one of available terminals as default at a time and you can not add multiple shell terminals.
If you don't want to install "Shell Launcher" plugin as suggested by #ian0411 then here is a quick way to change/select default terminal.
Press "Ctrl + Shift + P" to open the Command Palette.
Type "Terminal: Select Default Shell" and hit enter. You will be prompted to select Git Bash, PowerShell or Cmd as shown below:
Note: This will change the default shell terminal but there is no harm changing it whenever you need to use another.
BTW, if you need to switch only between Cmd & Powershell then you can type cmd or powershell (in already opened terminal) to switch to desired terminal. But it would not work for Git Bash.
I don't see this in the above, but read all the answers. I think this is the best approach for what is supported right now. I believe, like myself, the OP simply wants to open VSCode, and down yonder on the terminal window, we just want a list of options to open from.
Yes, you can open the command, "Terminal: Select Default Shell" and loop through that to add various types of terminals...
Followed by:
I don't know when this option was added to the dropdown, but look! No need to start by looking up the command. I think this is a lot smoother than any other answer, but it still results in the annoying overwrite of your default term to whatever your last choice was before leaving session.
Here, we can more easily open the Select Default Shell - it should support "Select New Shell". Simple, you'd think. Hopefully someone adds that soon or I have time to contribute.
I'm fairly certain that these are old-style settings.json and won't work as discussed in VS Code 2021. The new style looks like:
...
"terminal.integrated.profiles.windows":
{ "Bash":
{ "path": ["C:\\Programs\\Git\\bin\\bash.exe"],
"icon": "terminal-bash",
},
"Command Prompt":
{ "path": ["${env:windir}\\System32\\cmd.exe"],
"args": [],
"icon": "terminal-cmd"
},
"PowerShell":
{ "path": ["C:\\Programs\\PowerShell\\pwsh.exe"],
"source": "PowerShell",
"args": [],
"icon": "terminal-powershell"
},
},
"terminal.integrated.defaultProfile.windows": "Bash"
...
That will get you access to Command and PowerShells and set bash as the default shell (my preference). If you want to launch a standalone application like git-bash, you will need something else.
As of https://code.visualstudio.com/updates/v1_35 you can now:
select from the pulldown menu directly above the terminal "Select Default Shell"
select the one you like
click the +
done
(the same goes for opening split screen: before this do 1 + 2 and then click the split screen button)
(although overriding the default but does no longer matter if this is your flow)
This can be done by adding a different key at the end. By just changing your example to:
// // 64-bit cmd if available, otherwise 32-bit
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\cmd.exe",
// // 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows2": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe",
// // Git Bash
"terminal.integrated.shell.windows3": "C:\\Program Files\\Git\\bin\\bash.exe",
Note that the key ...shell.windows is changed to ...shell.windows2 and ...shell.windows3.
Follow-up finding: I've noticed that once restart of the IDE, only the first terminal gets displayed. I had to reopen the settings and save it once to get both the terminals again. Will post if any better solution available.
In the terminal tab, there's a Split Terminal button. Works like a charm
To open the multiple terminal please check the screen shot for the same(on the right bottom of the visual studio code their will be a dropdown and just after it, their is +(plus) icon . On pressing it the new terminal will open.).
The recommended way to automatically open multiple terminal windows is to use the Tasks feature. See Automating launching of terminals in the VS Code documentation.
For WSL Ubuntu on Windows terminal:
File -> preferences -> settings -> click code icon in top right
Enter the following:
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\wsl.exe",
"git.enableSmartCommit": true
}