Abstract: VsCode is an open source editor with powerful functions. With the variety of plug-ins available, VsCode can do a lot more. In the process of using, there are a lot of skills, master some skills for the later code will also be a lot easier.
This article is from the Huawei cloud community “VSCode Usage Tips”, written by: Xiao Cong is not xiao Cong ~.
VsCode is an open source editor with powerful features. With the variety of plug-ins available, VsCode can do a lot more. In the process of using, there are a lot of skills, master some skills for the later code will also be a lot easier.
1. View logs
Step 1 Run Ctrl+Shift+P
Step 2. Search for showlogs
2. Open the VSCode configuration file settings.json
Step 1 Run Ctrl+Shift+P
Step 2. Search Open Settings (JSON)
3. View logs about remote connection
Add the following parameters to the VSCode configuration file settings.json
"remote.SSH.showLoginTerminal": true,
Copy the code
4. VSCode background is set to Bean paste green
Add the following parameters to the VSCode configuration file settings.json
"workbench.colorTheme": "Atom One Light",
"workbench.colorCustomizations": {
"[Atom One Light]": {
"editor.background": "#C7EDCC",
"sideBar.background": "#e7f0e7",
"activityBar.background": "#C7EDCC",
},
},
Copy the code
5. Set the remote plug-in installed by default
In VSCode configuration file Settings. Add remote json. SSH. DefaultExtensions parameters, such as automatic install Python and Maven plug-ins, can be configured as follows.
"remote.SSH.defaultExtensions": [
"ms-python.python",
"vscjava.vscode-maven"
],
Copy the code
6. Install the specified local plug-in to the remote device or install the remote plug-in to the local device
Step 1 Run Ctrl+Shift+P
Step 2 Search for Install Local and select it as required
7. Use Git repositories remotely
7.1 local Host configuration, this article takes Windows10 as an example
Step 1 Install OpenSSH
Step 2 Start PowerShell as an administrator and run the following commands as required:
-
Start the SSHD service:
Get-WindowsCapability -Online | ? Name -like ‘OpenSSH*’ Start-Service sshd Set-Service -Name sshd -StartupType ‘Automatic’ Get-NetFirewallRule -Name ssh New-NetFirewallRule -Name sshd -DisplayName ‘OpenSSH Server (sshd)’ -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
-
Allow Windows to automatically run SSH Agent:
Set-Service ssh-agent -StartupType Automatic Start-Service ssh-agent Get-Service ssh-agent
-
Add a private key pair to a running agent:
Ssh-add.exe.\id_rsa # The path is ssh-add.exe -l where the private key is to be added
Step 3 Edit the local sshconfig file (such as ~\.ssh\config) and add the ForwardAgentyes configuration, as shown in the following.
Host my_host
HostName x.x.x.x
Port x
User x
IdentityFile xx
ForwardAgent yes
Copy the code
If ForwardAgentyes is added to all hosts by default, you can add the following configuration:
Host *
ForwardAgent yes
Copy the code
7.2 Flexible Remote Use of Git Repositories
How to use Git:
Code.visualstudio.com/docs/introv…
More Git function using details can read VSCode code.visualstudio.com/docs/editor official document…
8. Install the plug-in remotely based on the offline package
Step 1 Go to vscode_marketplace on the official website of VSCode plug-in to search for A plug-in to be installed
Step 2 Click A plug-in details to download the plug-in offline installation package. As shown in the figure:
Step 3. Drag the downloaded. Vsix file to the remote container
Step 4. Right-click the file and select Install ExtensionVSIX
9. After the remote server is restarted, you need to delete the local known_hosts to connect to the remote server
StrictHostKeyChecking No and UserKnownHostsFile=/dev/null can be configured in the local sshconfig file, as shown in the following:
Host my_host
HostName x.x.x.x
Port x
User x
IdentityFile xx
ForwardAgent yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Copy the code
Warning: If the preceding configuration parameters are added, the known_hosts file is ignored during SSH login, causing security risks
10. Code debugging cannot enter the source code
If you already have the launch.json file, go to Step 3. Step 1: Open the launch.json file. It can be opened in any of the following ways:
- Method 1: Click the Run (Ctrl+Shift+D) button on the left menu bar, and then click Create a launch.json file. As shown below:
- Method 2: Click the Run > Open Configurations button in the top menu bar
Step 2: Select a language
If you need to set The Python language, Select Python File from Select a Debug Configuration. The operations in other languages are similar. As shown below:
Step 3: Edit launch.json and add the justMyCode”:false configuration, as shown below:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For More information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version" : "0.2.0," "configurations: [{" name ":" Python: the current file ", "type" : "Python", "request" : "launch", "the program" : "${file}", "console" : "integratedTerminal", "justMyCode": false } ] }Copy the code
11. When submitting the code, a dialog box is displayed indicating that the user name and mailbox are incorrectly configured
In terminal, run the following command and try again:
Git config --global user.name my_name # git config --global user.name my_name #Copy the code
12. Do not automatically upgrade VSCode
Step 1 Run Ctrl+Shift+P
Step 2. Search Open Settings (JSON)
Step 3 Add the following parameter “update.mode”:”manual” to configuration file settings.json.
13. Disable automatic upgrade of VSCode plug-in versions
Step 1 Run Ctrl+Shift+P
Step 2. Search Open Settings (JSON)
Step 3 Add extensions. AutoUpdate :false to configuration file settings.json
Click to follow, the first time to learn about Huawei cloud fresh technology ~