VS Code highlight modified lines - visual-studio-code

I am unable to find a setting to enable modified/changed/new lines highlight in editor. Like on this screenshot from the video about angular2 by google.
How to enable modified line hilight?

This is connected with your file being under revision control. If you have your files in git and open the folder in VS Code. You will see the colors depending on the change you've made.
Check section about Gutter indicators.

I had the same problem try launching vscode in terminal like: code your-project-dictionary.
If code command cannot be found, enable code in shell:
Open VSCode press CMD+Shift+P. A dialog will be shown: Type in "shell" and click on Shell Command: Install 'code' command in PATH. Now you can launch VSCode in terminal. This solved my issue with highlighting changed files on VSC Project Structure!

I had the same issue and turns out that for me it was a bug in git client. Reinstalling git resolved the problem with changes highlighting. Ensure that you are using latest git client. Then reopen VSCode, reopen project/folder.

It seems you should open with folder, rather than open just files.
open just files:
img example
open with folder:
img example
anyway, in terminal, use code xxxx(folder name) to open project, or right click the floder and choose open with vscode in context

Tip: must open the real directory, but not a link dir
if you add fold to a workspace, also must add a real direcotory
{
"folders": [
{
"path": "."
},
{
"path": "../src/xxx/"
},
{ # ../golang/src/test must be a real dir
"path": "../golang/src/test"
}
],

Related

Is it possible to quickly swap workspaces using the integrated terminal in Visual Studio Code?

I would like to make it so that when I'm traversing directories using the integrated terminal, running code . opens the current working directory in the integrated terminal within the current VSCode window, "discarding"/closing the currently opened workspace, instead of opening a new window for that folder. Is this possible? If not, what would be a similar solution?
You can use code -r .
code --help gives the following description:
-r --reuse-window Force to open a file or folder in an already opened window.
Another source is Visual Studio Code Tips and Tricks
As #ltomase found in their answer (and exanding on their answer), you can use the -r option of the code command. The doc comment for this option in the --help menu says this:
Force to open a file or folder in an already opened window.
There are other approaches not involving the command-line:
Open command palette and use the File: Open Workspace from File... command to open workspace files (.code-workspace), or
Open command palette and use the File: Open Folder... command to open folders (keyboard shortcut: ctrl+K , ctrl+o).
Use alt+f to open the File menu, then use keyboard navigation to go to "Open Recent" and then select a recent workspace to open.

Git-Bash in Visual Studio Code from the D drive

I am trying to use Git Bash as a terminal in Visual Studio Code, however I am not able to find it in the terminal profiles. The option for Git Bash doesn't appear in the available terminals. I have installed Bash already. However I did it in the D drive. Is there a way to make git-bash available to choose as a terminal or even make it the default one from the D drive?
You can create your own profile in the setting.json file and set the default terminal profile to it, like so (for Windows):
"terminal.integrated.profiles.windows": {
"My Git Bash":{
"path": "D:\\GitbashLocation\\git-bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "My Git Bash",
Note that you can name your profile whatever you want. You may also need to restart Visual Studio Code after defining your profile so it detects it when you specify it in the terminal.integrated.defaultProfile.windows setting.
I was also struggling with the same but finally got it fixed with thanks to the final bit of help needed from #Timothy G's answer, with the help of other posts here on stack as well.
Let me just post a step-by-step solution adding to the #Timothy G's answer below, JIC if you're still struggling with it and also for future visitors.
Note: I'm using VS Code Insiders build (Version: 1.64.0-insider(user setup)) on Windows, but should work for other builds as well.
Since you have already downloaded git bash, ignore the 1st step.
Download git bash from the https://git-scm.com/download/win.
Open VS Code ⟹ File ⟹ Preferences ⟹ Settings. (Ctrl + ,).
There will be a search bar on top.
Search for terminal.integrated.profiles.windows.
A result will come up that would look like this
Terminal › Integrated › Profiles: Windows
The Windows profiles to present when creating a new terminal via the terminal dropdown. Use the source property to automatically detect the shell's location. Or set the path property manually with an optional args.
Set an existing profile to null to hide the profile from the list, for example: "Ubuntu-20.04 (WSL)": null.
Edit in settings.json
Click on Edit in settings.json.
Then another window will pop up next to the Settings tab called settings.json
Copy and paste this inside the settings.json. Remember to set the “path” to your git bash.exe in the bin folder
You can remove the first two lines if you don't need it and do Ctrl + S to save the JSON settings.
{
"workbench.colorTheme": "Default Dark+",
"files.autoSave": "afterDelay",
"terminal.integrated.profiles.windows": {
"My Git Bash":{
"path": "I:\\Projects\\git\\bin\\bash.exe",
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "My Git Bash",
}
After adding the above, select the “Settings” tab again and search for terminal.integrated.defaultProfile.windows
Then you'll be presented with a terminal feature like this with a drop-down.
Terminal › Integrated › Default Profile: Windows
The default profile used on Windows. This setting will currently be ignored if either terminal.integrated.shell.windows or terminal.integrated.shellArgs.windows are set.
Under the drop-down, select the profile My Git Bash then you're
all set.
Then got to ⟹ View ⟹ Terminal. (Ctrl + `)
It should now show up with the bash terminal. If it doesn't, restart VSC and it'll work for sure.
In order to make Timothy G.'s answer work, first, add the new profile as described in the VSCode documentation:
Step 1: "To create a new profile, run the Terminal: Select Default Profile command and activate the configure button on the right side of the shell to base it on. This will add a new entry to your settings that can be tweaked manually in your settings.json file."
https://code.visualstudio.com/docs/editor/integrated-terminal#_terminal-profiles
Type in a new name in the input box after you click the "configure" button. This will create a new profile in settings.json with your new name cloned from an existing profile (against which you clicked the "configure" button).
Step 2: Go to the settings.json file. You will see the profile with your new name added there. Update it with Timothy G's settings. Here is how mine looks like:
{
"My Git Bash": {
"path": "D:\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
"terminal.integrated.defaultProfile.windows": "My Git Bash"
}
Step 3: Save and restart VSCode. The next time the terminal will open with Git Bash.

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:

Visual Studio Code edit file

When I try to edit a file in visual studio code, I type the command 'code filename.ps1' and the code used to automatically open as a second tab in the editor.
Now, when I do the same thing, it opens in a new window. I have not changed anything in my settings and I can't find an associated Preference that controls this.
Anyone know exactly the default setting that I need to look at?
According to CLI Options this should work:
code -r filename.ps1
>
-r or --reuse-window
Forces opening a file or folder in the last active window.

How to open a file from the integrated terminal in Visual Studio Code?

Is there a way of opening a file from the terminal in Visual Studio Code that opens in the same vscode instance that runs the terminal? Similar to c9 tool in Cloud9.
I'm aware of the code tool, but when you run code something.php from the integrated terminal it opens a new vscode instance, which is not what I want...
You can use -r or --reuse-window command line option.
code -r something.php
just
code file_name
I tried it on Win10 and on Linux (Ubuntu)
I don't know what operating system you're using, but on MacOS you can just say open filename.ext in the integrated terminal, and it will open a new tab in the same VSCode instance, ready for you to edit.
If you are having command not found: code in macOS, use a full path to it.
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code -r [filename]
Open Visual Studio Code
Press CMD + SHIFT + P (this opens "Command Palette")
Type shell command
Select “Install code command in path”
Navigate to any project from the terminal, and type code .
If it didn't work, select “Uninstall code command from path” first, then reinstall it again.
I use code -r . to open the current directory in the main window.
You can use the code command from the CLI to open a file, but if you want it to open in the existing window, either use code -r <file> as mentioned in other answers (which does work for me on Ubuntu Linux), or, if -r does not work (under WSL?), make sure window.openFilesInNewWindow is either off or default in settings.json or the in VS Code settings UI, then use code <file>.
Many things can be found in open --help
A work around that worked for me on MacOS is:
open -a 'Visual Studio Code.app' something.php
in the version 1.31.0 that I have installed, on Windows 7, the only way I found to do this is to e.g. change the file associations in system so that .cproj and .cs files are opened by Visual Studio Code by default, and type "filename.cs" in Terminal to open file by that name in the same window... -r option is not working for the first call (opens a new window), but with each subsequent call that same window is correctly reused. ok can't get to open whole directories this way - it's a bit shoddy anyway. probably it would be more convenient to use an outside shell and work with "-r" option
VSCode 1.64 (Jan. 2022) comes with a new command:
Keyboard Navigable Links
Previously, link navigation in the terminal required the use of a mouse.
Now, links can be opened using only the keyboard via the following commands:
Terminal: Open Detected Link... to view all links (web, file, word)
Terminal: Open Last Web Link... ex: https://github.com/microsoft/vscode
Terminal: Open Last File Link... ex: /Users/user/repo/file.txt
Check if the last command Terminal: Open Last File Link... would help in your case.
See also "Terminal shell integration"