Abstract: VsCode is an open source editor with powerful functions. With a variety of plug-ins, this makes VsCode do more things. In the process of using, there are also many skills, and mastering some skills will make it easier to write code later.
This article is shared from Huawei Cloud Community " VSCode Use Skills ", author: Xiao Cong is not Xiao Cong~.
VsCode is an open source editor with powerful functions. With a variety of plug-ins, this makes VsCode do more things. In the process of using, there are also many skills, and mastering some skills will make it easier to write code later.
1. View log
Step 1. Execute Ctrl+Shift+P
Step 2. Search for show logs
2. Open the VSCode configuration file settings.json
Step 1. Execute Ctrl+Shift+P
Step 2. Search for Open Settings (JSON)
3. View the log when connecting to the remote
Add the following parameters in the VSCode configuration file settings.json
"remote.SSH.showLoginTerminal": true,
4. VSCode background configuration is bean paste green
Add the following parameters in 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",
},
},
5. Set the plug-ins installed by default on the remote
Add the remote.SSH.defaultExtensions parameter in the VSCode configuration file settings.json, such as automatic installation of Python and Maven plug-ins, the configuration can be as follows.
"remote.SSH.defaultExtensions": [
"ms-python.python",
"vscjava.vscode-maven"
],
6. Install the specified local plug-in to the remote or install the remote plug-in locally
Step 1. Execute Ctrl+Shift+P
Step 2. Search for install local and select as needed
7. Use Git Repository Remotely
7.1 Local host configuration, this article takes Windows 10 system as an example
Step 1. Install OpenSSH
Step 2. Start PowerShell as an administrator and execute the following commands as needed:
- 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 the private key pair to the running agent:
ssh-add.exe .\id_rsa #路径为待添加私钥的位置 ssh-add.exe -L
Step 3. Edit the local ssh config (such as ~.ssh\config) file and add the configuration ForwardAgent yes, as shown below.
Host my_host
HostName x.x.x.x
Port x
User x
IdentityFile xx
ForwardAgent yes
If ForwardAgent yes is added to all Hosts by default, the configuration can be added as follows:
`Host *
ForwardAgent yes `
7.2 Flexible use of Git repository remotely
For a brief Git operation guide video, please refer to the VSCode video tutorial (3 minutes 54 seconds): https://code.visualstudio.com/docs/introvideos/versioncontrol
For more Git function usage details, please read the official VSCode documentation
https://code.visualstudio.com/docs/editor/versioncontrol
8. Install plugins remotely based on offline packages
Step 1. Go to the VSCode plugin official website vscode_marketplace to search for the A plugin to be installed
Step 2. Click to enter the details of plug-in A and download the offline installation package of the plug-in. as the picture shows:
Step 3. Drag the downloaded .vsix file to the remote container
Step 4. Right-click the file and select Install Extension VSIX
9. After the remote restart, you need to delete the local known_hosts to connect
You can configure the parameters "StrictHostKeyChecking no" and "UserKnownHostsFile=/dev/null" for this container in the local ssh config file, as shown in the following reference:
Host my_host
HostName x.x.x.x
Port x
User x
IdentityFile xx
ForwardAgent yes
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
Tip: Adding the above configuration parameters will ignore the known_hosts file during SSH login, which is a security risk
10. Cannot enter the source code during code debugging
If you already have a launch.json file, please go directly 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 in 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 upper menu bar
Step 2: Choose a language
If you need to set the Python language, select Python File in the Select a debug configuration that pops up. The operations in other languages are similar. As shown below:
Step 3: Edit launch.json, add justMyCode": false configuration, as shown in the figure 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: 当前文件",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"justMyCode": false
}
]
}
11. When submitting the code, a dialog box pops up to prompt the user name and user mailbox configuration error
In the terminal, execute the following command, and then retry the submission:
git config --global user.email my_email #改为你的用户邮箱
git config --global user.name my_name #改为你的用户名
12. Prohibit automatic upgrade of VSCode version
Step 1. Execute Ctrl+Shift+P
Step 2. Search for Open Settings (JSON)
Step 3. Add the following parameters in the configuration file settings.json
"update.mode": "manual",
13. It is forbidden to automatically upgrade the plug-in version of VSCode
Step 1. Execute Ctrl+Shift+P
Step 2. Search for Open Settings (JSON)
Step 3. Add the following parameters in the configuration file settings.json
"extensions.autoUpdate": false,
Click to follow, and learn about Huawei Cloud's fresh technology for the first time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。