VSCode

 

目錄

  • Download
  • VS Code Settings
  • Disable auto update
  •  

 


Download

 

https://update.code.visualstudio.com/{version}/win32-x64-archive/stable

ie.

https://update.code.visualstudio.com/1.61.1/win32-x64-archive/stable

 


VS Code Settings

 

設定 UI Lang

"Ctrl+Shift+P" 找 display

VS Code provides two different scopes for settings:

  • User Settings - Settings that apply globally to any instance of VS Code you open.
  • Workspace Settings - Settings stored inside your workspace and only apply when the workspace is opened.

Workspace Settings

A VS Code "workspace" is usually just your project root folder.

settings.json in the workspace root.

Workspace settings as well as debugging and task configurations are stored at the root in a .vscode folder.

User Settings

%APPDATA%\Code\User\settings.json

Preferences

File > Preferences > Settings (Ctrl+,)

 


Disable auto update

 

[A]

"Ctrl+," 後找 "update"

[B]

%APPDATA%\Code\User\settings.json

{
    ...
    "update.mode": "none",
}

 

 


Hidden File

 

[A] "Ctrl+,"

search “files:exclude”

[B] .vscode/settings.json

{
    "files.exclude": {
        "**/.terraform*": true,
        "**/*.pyc": true
    },
}

Tips: File Explorer

  • Open the File Explorer with ctrl + b
  • Close a file with ctrl + w
  • Save a file with ctrl + s
     

Terminal(ssh) env variable

 

%APPDATA%\Code\User\settings.json

{
    "terminal.integrated.env.linux": {
        "GIT_AUTHOR_NAME": "888"
    }
}

 


Hotkey

 

Ctrl + Shift + X      # Managing extensions

Ctrl + Shift + E      # Explorer

在 Explorer 介面時

Ctrl + `                 # Termail

 


Extension(vsix)

 

extension: .vsix

 

 


Extension: sftp

 

sftp

publisher:"liximomo"

Settings

Ctrl+Shift+P > run "SFTP: config" command

"SFTP expects to work at a folder."

> "Open Folder" 選 ".vscode" Folder, 之後就會建立 sftp.json

Configure

A basic configuration file will appear named sftp.json under the .vscode directory.

{
    "name": "Profile Name",
    "host": "name_of_remote_host",
    "protocol": "ftp",
    "port": 21,
    "secure": true,
    "username": "username",
    "remotePath": "/public_html/project",  <---- This is the path which will be downloaded if you "Download Project"
    "password": "password",  
    "uploadOnSave": true
}

 


Extension: Remote-SSH

 

它係透過系統的 ssh.exe 去建立 ssh shell 及 tunnel

  • C:\Windows\System32\OpenSSH\ssh.exe

Marketplace

Repository

VS Code Server

By default, the "VS Code Server" is installed and maintained by the Remote

  • No source code needs to be on your local machine
  • runs commands and other extensions directly on the remote machine

Set the "remote.SSH.configFile" property in your User settings.json file

 tree -L 3 .vscode-server/

.vscode-server/
├── cli
│   └── servers
│       ├── lru.json
│       └── Stable-863d2581ecda6849923a2118d93a088b0745d9d6  # 有個 node 在入面
├── code-863d2581ecda6849923a2118d93a088b0745d9d6    # ELF 64-bit LSB pie executable
├── data
│   ├── CachedProfilesData
│   │   └── __default__profile__
│   ├── logs
│   │   └── 20240331T131850
│   ├── Machine
│   ├── machineid
│   └── User
│       ├── globalStorage
│       ├── History
│       └── workspaceStorage
└── extensions
    └── extensions.json

Notes

1 GB RAM is required, at least 2 GB RAM and a 2-core CPU is recommended.

A compromised remote could use the VS Code Remote connection to execute code on your local machine.

Settings

Ctrl+,

remote.SSH.remotePlatform

configFile

%userprofile%/.ssh/config

mini

Host awscli
    HostName 192.168.88.171
    User root

long

Host WAF-Server
    HostName N.N.N.N
    Port 22
    User yourname
    IdentityFile MySshKeys/waf.pem

Host              An easy-to-remember alias for your host machine.

HostName     The hostname / IP address of the server

IdentityFile 的位置對應 %USERPROFILE%

"Always installed" extensions#

If there are extensions that you would like to always have installed on any SSH host, you can specify

which ones using the remote.SSH.defaultExtensions property in settings.json.

"Remote.SSH: Remote Server Listen On Socket"

/etc/ssh/sshd_config

AllowStreamLocalForwarding yes

Remote Environment Variables

# Default 有以下 Env
TERM_PROGRAM=vscode

Kill

Ctrl + Shift + p

Remote-SSH: kill VS Code Server on Host

commit_id

Local VSCode: GUI > Help > about

Manual install VSCode on Remote

commit_id=ee2b180d582a7f601fa6ecfdad8d9fd269ab1884

mkdir -p ~/.vscode-server/bin/${commit_id}

cd !?

# Download url is: https://update.code.visualstudio.com/commit:${commit_id}/server-linux-x64/stable

# -s, --silent, -S, --show-error, -L / --location

# Unzip: 62M -> 209M

curl -sSL "https://update.code.visualstudio.com/commit:${commit_id}/server-linux-x64/stable" -o ${commit_id}.tar.gz

tar -zxf /tmp/vscode-server-linux-x64.tar.gz  --strip 1

Login with ssh key

Host remotehost.yourcompany.com
    IdentityFile C:\ssh_key\ssh.key
    ...

Key Format

# 錯誤

-----BEGIN OPENSSH PRIVATE KEY-----

# Ok

----BEGIN RSA PRIVATE KEY-----

Toubleshoot

F1 > Developer: Set Log Level

F1 > View: Open View > Log (Shared)

F1 > View: Open View > Log (Window)

F1 > View: Open View > Log (Remote Server)

 

 


Fold & un-Fold

 

Fold All: Ctrl + k, 0

Unfold All: Ctrl + k, j

Ctrl + k, 1: namspace

Ctrl + k, 2: class

Ctrl + k, 3: methods

Ctrl + k, 4: blocks

Ctrl + k, [ or Ctrl + k + ]: current cursor block

 


Indentation

 

Indent

減小縮排: Shift + Tab

 

Reformat indentation

 

Hotkey: Shift + Alt + F

 * python 須要安 autopep8

 


Plugin

 

# python 的環境

ms-python.python

 


Workspace

 

Hotkey: Ctrl+,

Workspace Settings Location: <YOUR_FOLDER>\.vscode\settings.json

User Settings Location: %appdata%\Code

 


Auto Complete

 

要在 Marketplace 安裝 Pylance

IntelliSense(Pylance) # Microsoft

You can trigger IntelliSense in any editor window by typing Ctrl+Space or

by typing a trigger character (such as the dot character (.) in JavaScript).

Visual Studio Code: Intellisense not working

原因1: 未安 Pylance

 


Virtual Environment

 

1) Open the Command Palette

"Ctrl+Shift+P" in your VSCode

2) Locate your Virtual Environment

Python: select interpreter > Enter interpreter path > Find

your-virtual-env > bin > python3.

3) 自動啟用

Settings (Ctrl+,)

Search "python.terminal.activateEnvironment"

 


Tips

 

[1] How to prevent Visual Studio Code from always reopening the previous files or folders?

Ctrl+,
"window.restoreWindows": "none"       # Default all

 

Creative Commons license icon Creative Commons license icon