VSCode配置(页面配置)
vscode下载地址:https://code.visualstudio.com/updates/
settings.json
cpp
# settings.json
{
"workbench.colorTheme": "Monokai",
"workbench.colorCustomizations": {
"[Monokai]":{
"sideBar.background": "#1e1f1c",
"editor.background": "#272822",
"editorWhitespace.foreground": "#5f5f5f",
"titleBar.activeBackground": "#1e3b5c",
"debugToolBar.border": "#f11054",
"titleBar.border":"#b11b34",
"tab.activeBackground": "#b11b34",
"editor.selectionHighlightBackground":"#f5dd09ab",
"editor.selectionBackground": "#e4d01ad3",
}
},
"editor.tokenColorCustomizations": {
"[Monokai]":{
"textMateRules": [
{ /* enum item */
"name": "Constants and enums",
"scope": [
"variable.other.constant",
"variable.other.enummember"
],
"settings": {
"foreground": "#4FC1FF",
}
},
{ /* 123456789 */
"name": "Number",
"scope": "constant.numeric",
"settings": {
"foreground": "#AC80FF"
}
},
{ /* 0x */
"name": "Units",
"scope": "keyword.other.unit",
"settings": {
"foreground": "#AC80FF"
}
},
{ /* //Comment */
"name": "Comment",
"scope": "comment",
"settings": {
"foreground": "#29961f"
}
},
{ /* 'x' "hello" ... */
"name": "String",
"scope": "string",
"settings": {
"foreground": "#E6DB74"
}
},
{ /* "%s %d %f %c ..." */
"name": "User-defined constant",
"scope": "constant.character, constant.other",
"settings": {
"foreground": "#E6DB74"
}
},
{ /* a,b,c i,j,k ... */
"name": "Variable",
"scope": "variable",
"settings": {
"fontStyle": "",
"foreground": "#e2e2e2"
}
},
{ /* if else for while return ... */
"name": "Keyword",
"scope": "keyword",
"settings": {
"foreground": "#F92672"
}
},
{ /* > < = ! + - */
"scope": "keyword.operator",
"settings": {
"foreground": "#d4d4d4"
}
},
{ /* sizeof */
"scope": [
"keyword.operator.expression",
"keyword.operator.cast",
"keyword.operator.sizeof",
"keyword.operator.alignof",
"keyword.operator.typeid",
"keyword.operator.alignas",
"keyword.operator.instanceof",
"keyword.operator.logical.python",
"keyword.operator.wordlike"
],
"settings": {
"foreground": "#ff80c0"
}
},
{ /* new */
"scope": [
"keyword.operator.new"
],
"settings": {
"foreground": "#6491c5"
}
},
{ /* void int char short long unsigned */
"name": "Storage",
"scope": "storage",
"settings": {
"foreground": "#ff80c0"
}
},
{ /* static extern */
"name": "Storage type",
"scope": "storage.type",
"settings": {
"fontStyle": "italic",
"foreground": "#ff80c0"
}
},
{ /* this self */
"name": "this.self",
"scope": "variable.language",
"settings": {
"foreground": "#ff91bf"
}
},
{ /* ClassName ... */
"name": "Class name",
"scope": [
"entity.name.type",
"entity.name.class",
"entity.name.namespace",
"entity.name.scope-resolution",
"entity.other.inherited-class"
],
"settings": {
"fontStyle": "",
"foreground": "#646bc5"
}
},
{ /* main test ... */
"name": "Function name",
"scope": "entity.name.function",
"settings": {
"fontStyle": "",
"foreground": "#28cdea"
}
},
{ /* argc argv ... */
"name": "Function argument",
"scope": "variable.parameter",
"settings": {
"foreground": "#c7c7c7"
}
},
{ /* define name */
"scope": [
"meta.preprocessor",
"entity.name.function.preprocessor"
],
"settings": {
"foreground": "#AC80FF"
}
},
]
}
},
"explorer.confirmDelete": false,
"remote.SSH.remotePlatform": {
"bd1": "linux",
"aj102c": "linux",
"b125": "linux",
"b115": "linux",
"dcu-team": "linux",
"local-docker": "linux",
"aj102-docker": "linux",
"10.32.237.30": "linux"
},
"cmake.configureOnOpen": true,
"files.exclude": {
"**/.github": true,
"**/.gitmodules": true,
"**/*.gitignore": true,
"**/*.o": true,
"**/*.scc": true,
"build": true
},
"files.autoGuessEncoding": true,
"editor.fontSize": 22,
"editor.lineHeight": 24,
"C_Cpp.updateChannel": "Insiders",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4,TabWidth: 4, ColumnLimit: 0}",
"editor.tabCompletion": "on",
"editor.renderWhitespace": "all",
"workbench.editorAssociations": {
"*.o": "default"
},
"update.mode": "none",
"C_Cpp.vcFormat.indent.namespaceContents": false,
"editor.detectIndentation": false,
"vsicons.dontShowNewVersionMessage": true,
"terminal.integrated.enableMultiLinePasteWarning": false,
"git.enableSmartCommit": true,
"Codegeex.Privacy": false,
"C_Cpp.inlayHints.parameterNames.suppressWhenArgumentContainsName": false,
"C_Cpp.inactiveRegionOpacity": 0.55,
"extensions.autoCheckUpdates": false,
"diffEditor.ignoreTrimWhitespace": false,
"git.ignoreLegacyWarning": true,
"cmake.showOptionsMovedNotification": false,
// "window.zoomLevel": -1,
"editor.tabSize": 8,
"window.zoomLevel": -0.5,// 左侧菜单栏的字体大小
"editor.mouseWheelZoom": true,// 按住ctrl可以设置代码的字体大小
"terminal.integrated.fontSize": 15, // 终端字体大小
"editor.wordWrap": "on", //终端自动换行
}
优化配置2
cpp
{
// ====== 主题与外观 ======
"workbench.colorTheme": "Monokai",
"workbench.colorCustomizations": {
"[Monokai]": {
"sideBar.background": "#1e1f1c",
"editor.background": "#272822",
"editorWhitespace.foreground": "#5f5f5f",
"titleBar.activeBackground": "#1e3b5c",
"debugToolBar.border": "#f11054",
"titleBar.border": "#b11b34",
"tab.activeBackground": "#b11b34",
"editor.selectionHighlightBackground": "#f5dd09ab",
"editor.selectionBackground": "#e4d01ad3",
"statusBar.background": "#1e3b5c",
"activityBar.background": "#1e1f1c",
"panel.background": "#1e1f1c"
}
},
// ====== 语法高亮优化 ======
"editor.tokenColorCustomizations": {
"[Monokai]": {
"textMateRules": [
{
"name": "Constants and enums",
"scope": ["variable.other.constant", "variable.other.enummember"],
"settings": { "foreground": "#4FC1FF" }
},
{
"name": "Number",
"scope": "constant.numeric",
"settings": { "foreground": "#AC80FF" }
},
{
"name": "Comment",
"scope": "comment",
"settings": { "foreground": "#29961f", "fontStyle": "italic" }
},
{
"name": "String",
"scope": "string",
"settings": { "foreground": "#E6DB74" }
},
{
"name": "Variable",
"scope": "variable",
"settings": { "foreground": "#e2e2e2" }
},
{
"name": "Keyword",
"scope": "keyword",
"settings": { "foreground": "#F92672" }
},
{
"scope": "keyword.operator",
"settings": { "foreground": "#d4d4d4" }
},
{
"name": "Storage",
"scope": "storage",
"settings": { "foreground": "#ff80c0" }
},
{
"name": "Class name",
"scope": ["entity.name.type", "entity.name.class"],
"settings": { "foreground": "#646bc5", "fontStyle": "bold" }
},
{
"name": "Function name",
"scope": "entity.name.function",
"settings": { "foreground": "#28cdea" }
},
{
"name": "Function argument",
"scope": "variable.parameter",
"settings": { "foreground": "#c7c7c7" }
}
]
}
},
// ====== 编辑器核心设置 ======
"editor.fontSize": 14,
"editor.lineHeight": 1.5,
"editor.fontFamily": "'Cascadia Code', 'Fira Code', 'Source Code Pro', Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": true,
"editor.autoIndent": "full",
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.formatOnType": true,
// ====== 代码编辑增强 ======
"editor.minimap.enabled": true,
"editor.renderWhitespace": "boundary",
"editor.renderControlCharacters": true,
"editor.renderLineHighlight": "all",
"editor.occurrencesHighlight": true,
"editor.selectionHighlight": true,
"editor.matchBrackets": "always",
"editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs": true,
"editor.wordWrap": "on",
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.organizeImports": true
},
// ====== 文件与资源管理器 ======
"explorer.confirmDelete": false,
"explorer.confirmDragAndDrop": false,
"files.autoSave": "onFocusChange",
"files.autoGuessEncoding": true,
"files.trimTrailingWhitespace": true,
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.hg": true,
"**/CVS": true,
"**/.DS_Store": true,
"**/Thumbs.db": true,
"**/*.o": true,
"**/*.so": true,
"**/*.a": true,
"**/build/": true,
"**/node_modules/": true,
"**/.vscode/": false
},
// ====== 终端设置 ======
"terminal.integrated.fontSize": 13,
"terminal.integrated.fontFamily": "'Cascadia Code', 'Fira Code', monospace",
"terminal.integrated.cursorBlinking": true,
"terminal.integrated.cursorStyle": "line",
"terminal.integrated.scrollback": 10000,
"terminal.integrated.enableMultiLinePasteWarning": false,
// ====== 工作区与窗口 ======
"window.zoomLevel": 0,
"workbench.startupEditor": "newUntitledFile",
"workbench.editor.highlightModifiedTabs": true,
"workbench.editor.enablePreview": false,
"workbench.iconTheme": "vscode-icons",
// ====== 远程开发 ======
"remote.SSH.remotePlatform": {
"bd1": "linux",
"aj102c": "linux",
"b125": "linux",
"b115": "linux",
"dcu-team": "linux",
"local-docker": "linux",
"aj102-docker": "linux",
"10.32.237.30": "linux"
},
// ====== 编程语言特定设置 ======
// C/C++ 配置
"C_Cpp.updateChannel": "Insiders",
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4, ColumnLimit: 0, AllowShortFunctionsOnASingleLine: None }",
"C_Cpp.inlayHints.parameterNames.enabled": true,
"C_Cpp.inlayHints.parameterNames.suppressWhenArgumentContainsName": false,
"C_Cpp.inactiveRegionOpacity": 0.55,
"C_Cpp.autoAddFileAssociations": true,
// CMake 配置
"cmake.configureOnOpen": true,
"cmake.showOptionsMovedNotification": false,
// ====== Git 配置 ======
"git.enableSmartCommit": true,
"git.confirmSync": false,
"git.autofetch": true,
"git.autofetchPeriod": 180,
"git.ignoreLegacyWarning": true,
// ====== 扩展与功能 ======
"extensions.autoCheckUpdates": false,
"update.mode": "none",
"debug.onTaskErrors": "showErrors",
// ====== 智能提示与补全 ======
"editor.quickSuggestions": {
"strings": true
},
"editor.suggestSelection": "first",
"editor.acceptSuggestionOnCommitCharacter": false,
"editor.wordBasedSuggestions": "matchingDocuments",
"editor.inlineSuggest.enabled": true,
// ====== 搜索配置 ======
"search.exclude": {
"**/node_modules": true,
"**/bower_components": true,
"**/*.code-search": true,
"**/build": true,
"**/dist": true
},
// ====== 其他优化 ======
"diffEditor.ignoreTrimWhitespace": false,
"editor.mouseWheelZoom": true,
"breadcrumbs.enabled": true,
"editor.smoothScrolling": true,
"editor.cursorSmoothCaretAnimation": "on",
"editor.accessibilitySupport": "off"
}
以下是对每个配置项的详细说明:
主题与外观配置
json
"workbench.colorTheme": "Monokai",
作用:设置VS Code的整体颜色主题为Monokai,这是一个对程序员友好的暗色主题。
json
"workbench.colorCustomizations": {
"[Monokai]": {
"sideBar.background": "#1e1f1c", // 侧边栏背景色,降低视觉干扰
"editor.background": "#272822", // 编辑器背景色,保护视力
"editorWhitespace.foreground": "#5f5f5f", // 空白字符显示颜色,便于识别缩进
"titleBar.activeBackground": "#1e3b5c", // 活动窗口标题栏背景
"debugToolBar.border": "#f11054", // 调试工具栏边框,突出显示
"titleBar.border": "#b11b34", // 标题栏边框
"tab.activeBackground": "#b11b34", // 活动标签页背景,快速定位
"editor.selectionHighlightBackground": "#f5dd09ab", // 选中文本高亮背景
"editor.selectionBackground": "#e4d01ad3", // 文本选择背景色
"statusBar.background": "#1e3b5c", // 状态栏背景,统一风格
"activityBar.background": "#1e1f1c", // 活动栏背景
"panel.background": "#1e1f1c" // 面板背景色
}
},
意义:统一IDE的视觉风格,减少视觉疲劳,重要元素高亮便于快速定位。
语法高亮优化
json
"editor.tokenColorCustomizations": {
"[Monokai]": {
"textMateRules": [
{
"name": "Constants and enums",
"scope": ["variable.other.constant", "variable.other.enummember"],
"settings": { "foreground": "#4FC1FF" } // 常量蓝色,易于识别
},
{
"name": "Number",
"scope": "constant.numeric",
"settings": { "foreground": "#AC80FF" } // 数字紫色,区分于变量
},
{
"name": "Comment",
"scope": "comment",
"settings": {
"foreground": "#29961f",
"fontStyle": "italic" // 注释绿色斜体,明显区别于代码
}
},
// ... 其他语法规则
]
}
},
意义:通过颜色和字体的精细区分,提高代码可读性,快速识别不同语法元素。
编辑器核心设置
json
"editor.fontSize": 14, // 适中的字体大小,平衡信息密度和可读性
"editor.lineHeight": 1.5, // 1.5倍行高,减少视觉拥挤
"editor.fontFamily": "'Cascadia Code', 'Fira Code', 'Source Code Pro', Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": true, // 启用字体连字,如 => 显示为⇒
"editor.tabSize": 4, // 标准缩进大小
"editor.insertSpaces": true, // 用空格代替制表符,保证跨平台一致性
"editor.detectIndentation": true, // 自动检测现有文件的缩进风格
"editor.autoIndent": "full", // 完整的自动缩进
"editor.formatOnSave": true, // 保存时自动格式化,保持代码风格统一
"editor.formatOnPaste": true, // 粘贴时自动格式化
"editor.formatOnType": true, // 输入时自动格式化
意义:建立统一的代码书写规范,自动化代码格式化,提高开发效率。
代码编辑增强
json
"editor.minimap.enabled": true, // 启用代码缩略图,快速导航大文件
"editor.renderWhitespace": "boundary", // 显示边界空白字符
"editor.renderControlCharacters": true, // 显示控制字符
"editor.renderLineHighlight": "all", // 高亮当前行
"editor.occurrencesHighlight": true, // 高亮相同符号的所有出现
"editor.selectionHighlight": true, // 高亮其他相同选择
"editor.matchBrackets": "always", // 总是匹配括号
"editor.bracketPairColorization.enabled": true, // 括号对颜色化,便于识别嵌套
"editor.guides.bracketPairs": true, // 显示括号对的引导线
"editor.wordWrap": "on", // 自动换行,避免水平滚动
"editor.codeActionsOnSave": {
"source.fixAll": true, // 保存时自动修复所有可修复问题
"source.organizeImports": true // 保存时自动整理import语句
},
意义:增强代码导航和阅读体验,减少错误,提高编码准确性。
文件与资源管理器
json
"explorer.confirmDelete": false, // 删除文件时不确认,提高操作效率
"explorer.confirmDragAndDrop": false, // 拖拽时不确认
"files.autoSave": "onFocusChange", // 失去焦点时自动保存,防止数据丢失
"files.autoGuessEncoding": true, // 自动猜测文件编码
"files.trimTrailingWhitespace": true, // 保存时删除行尾空格
"files.insertFinalNewline": true, // 文件末尾自动添加空行
"files.trimFinalNewlines": true, // 整理文件末尾空行
"files.exclude": {
"**/.git": true, // 隐藏Git相关文件
"**/*.o": true, // 隐藏编译目标文件
"**/build/": true, // 隐藏构建目录
"**/node_modules/": true, // 隐藏node模块
"**/.vscode/": false // 显示.vscode配置目录
},
意义:优化文件操作体验,自动维护代码整洁,隐藏无关文件减少干扰。
终端设置
json
"terminal.integrated.fontSize": 13, // 终端字体稍小于编辑器
"terminal.integrated.fontFamily": "'Cascadia Code', 'Fira Code', monospace",
"terminal.integrated.cursorBlinking": true, // 光标闪烁,易于定位
"terminal.integrated.cursorStyle": "line", // 线状光标
"terminal.integrated.scrollback": 10000, // 保留10000行历史
"terminal.integrated.enableMultiLinePasteWarning": false, // 禁用多行粘贴警告
意义:提供舒适的命令行体验,与编辑器风格一致。
工作区与窗口
json
"window.zoomLevel": 0, // 默认缩放级别
"workbench.startupEditor": "newUntitledFile", // 启动时新建无标题文件
"workbench.editor.highlightModifiedTabs": true, // 高亮修改过的标签页
"workbench.editor.enablePreview": false, // 禁用预览模式,避免意外覆盖
"workbench.iconTheme": "vscode-icons", // 使用文件类型图标主题
意义:优化工作区布局和文件管理体验。
远程开发
json
"remote.SSH.remotePlatform": {
"bd1": "linux", // 指定各远程主机的平台类型
"aj102c": "linux",
// ... 其他主机配置
},
意义:优化远程开发体验,确保正确的平台检测。
编程语言特定设置
C/C++ 配置
json
"C_Cpp.updateChannel": "Insiders", // 使用最新特性
"C_Cpp.clang_format_fallbackStyle": "{ BasedOnStyle: Google, IndentWidth: 4, TabWidth: 4, ColumnLimit: 0, AllowShortFunctionsOnASingleLine: None }",
"C_Cpp.inlayHints.parameterNames.enabled": true, // 显示参数名提示
"C_Cpp.inlayHints.parameterNames.suppressWhenArgumentContainsName": false,
"C_Cpp.inactiveRegionOpacity": 0.55, // 非活动区域半透明
"C_Cpp.autoAddFileAssociations": true, // 自动添加文件关联
意义:针对C/C++开发的专门优化,提供更好的代码分析和提示。
CMake 配置
json
"cmake.configureOnOpen": true, // 打开时自动配置CMake
"cmake.showOptionsMovedNotification": false, // 不显示选项移动通知
意义:简化CMake项目配置流程。
Git 配置
json
"git.enableSmartCommit": true, // 智能提交,自动暂存所有更改
"git.confirmSync": false, // 同步前不确认
"git.autofetch": true, // 自动获取远程更新
"git.autofetchPeriod": 180, // 每3分钟自动获取
"git.ignoreLegacyWarning": true, // 忽略旧版Git警告
意义:优化版本控制工作流,自动化常规操作。
扩展与功能
json
"extensions.autoCheckUpdates": false, // 不自动检查扩展更新
"update.mode": "none", // 禁用自动更新
"debug.onTaskErrors": "showErrors", // 调试时显示错误
意义:减少干扰,保持开发环境稳定。
智能提示与补全
json
"editor.quickSuggestions": {
"strings": true // 在字符串中启用快速建议
},
"editor.suggestSelection": "first", // 优先选择第一个建议
"editor.acceptSuggestionOnCommitCharacter": false, // 不按提交字符接受建议
"editor.wordBasedSuggestions": "matchingDocuments", // 基于文档的单词建议
"editor.inlineSuggest.enabled": true, // 启用行内建议
意义:提供智能的代码补全,加速编码过程。
搜索配置
json
"search.exclude": {
"**/node_modules": true, // 排除node_modules目录
"**/build": true, // 排除构建目录
"**/dist": true // 排除分发目录
},
意义:优化搜索性能,排除无关目录。
其他优化
json
"diffEditor.ignoreTrimWhitespace": false, // 差异比较不忽略空白
"editor.mouseWheelZoom": true, // 鼠标滚轮缩放
"breadcrumbs.enabled": true, // 启用面包屑导航
"editor.smoothScrolling": true, // 平滑滚动
"editor.cursorSmoothCaretAnimation": "on", // 光标平滑动画
"editor.accessibilitySupport": "off" // 关闭辅助功能支持(性能优化)
意义:提供流畅的用户体验和性能优化。
下载 VS Code Server
powershell
# 以管理员身份打开PowerShell
$commitId = "6f17636121051a53c88d3e605c491d22af2ba755"
$url = "https://update.code.visualstudio.com/commit:${commitId}/server-linux-x64/stable"
$output = "vscode-server-linux-x64.tar.gz"
# 下载文件
Invoke-WebRequest -Uri $url -OutFile $output
Write-Host "下载完成: $output"
使用PowerShell多源尝试下载VS Code Server
powershell
# 在PowerShell中执行多源下载脚本
$commitId = "6f17636121051a53c88d3e605c491d22af2ba755"
$output = "vscode-server-linux-x64.tar.gz"
# 多个下载源
$urls = @(
"https://vscode.cdn.azure.cn/stable/$commitId/vscode-server-linux-x64.tar.gz",
"https://mirrors.cloud.tencent.com/vscode/stable/$commitId/vscode-server-linux-x64.tar.gz",
"https://mirrors.huaweicloud.com/vscode/stable/$commitId/vscode-server-linux-x64.tar.gz",
"https://update.code.visualstudio.com/commit:${commitId}/server-linux-x64/stable"
)
foreach ($url in $urls) {
Write-Host "尝试下载: $url"
try {
Invoke-WebRequest -Uri $url -OutFile $output -TimeoutSec 30
Write-Host "✅ 下载成功!" -ForegroundColor Green
break
}
catch {
Write-Host "❌ 下载失败: $($_.Exception.Message)" -ForegroundColor Red
if (Test-Path $output) { Remove-Item $output }
}
}
在Windows上下载VS Code Server 再传输到Linux服务器
1. 在Windows上下载VS Code Server
方法一:使用浏览器下载
-
打开浏览器,访问以下URL(将COMMIT_ID替换为你的):
https://update.code.visualstudio.com/commit:6f17636121051a53c88d3e605c491d22af2ba755/server-linux-x64/stable -
文件会自动下载为
stable文件,重命名为:vscode-server-linux-x64.tar.gz
方法二:使用PowerShell下载
powershell
# 以管理员身份打开PowerShell
$commitId = "6f17636121051a53c88d3e605c491d22af2ba755"
$url = "https://update.code.visualstudio.com/commit:${commitId}/server-linux-x64/stable"
$output = "vscode-server-linux-x64.tar.gz"
# 下载文件
Invoke-WebRequest -Uri $url -OutFile $output
Write-Host "下载完成: $output"
2. 传输文件到Linux服务器
方法一:使用scp命令(推荐)
powershell
# 在PowerShell中执行
scp .\vscode-server-linux-x64.tar.gz 用户名@服务器IP:/tmp/
# 示例:
scp .\vscode-server-linux-x64.tar.gz user@192.168.1.100:/tmp/
scp .\vscode-server-linux-x64.tar.gz root@your-server.com:/tmp/
方法二:使用WinSCP(图形化工具)
- 下载安装 WinSCP
- 连接你的Linux服务器
- 直接将文件拖拽到服务器的
/tmp/目录
方法三:使用FileZilla
- 下载安装 FileZilla
- 使用SFTP连接服务器
- 上传文件到
/tmp/目录
3. 在Linux服务器上安装
通过SSH连接到Linux服务器,执行以下命令:
bash
# 设置commit ID
COMMIT_ID="6f17636121051a53c88d3e605c491d22af2ba755"
# 创建目标目录
mkdir -p ~/.vscode-server/bin/${COMMIT_ID}
# 解压到目标目录
tar -xzf /tmp/vscode-server-linux-x64.tar.gz -C ~/.vscode-server/bin/${COMMIT_ID} --strip-components 1
# 设置执行权限
chmod +x ~/.vscode-server/bin/${COMMIT_ID}/bin/code-server
# 验证安装
ls -la ~/.vscode-server/bin/${COMMIT_ID}/
4. 完整的安装脚本
在Linux服务器上创建安装脚本 install_vscode_server.sh:
bash
#!/bin/bash
COMMIT_ID="6f17636121051a53c88d3e605c491d22af2ba755"
SOURCE_FILE="/tmp/vscode-server-linux-x64.tar.gz"
TARGET_DIR="$HOME/.vscode-server/bin/$COMMIT_ID"
echo "=== 开始安装 VS Code Server ==="
# 检查源文件是否存在
if [ ! -f "$SOURCE_FILE" ]; then
echo "错误: 未找到文件 $SOURCE_FILE"
echo "请先将 vscode-server-linux-x64.tar.gz 上传到 /tmp/"
exit 1
fi
# 清理旧安装(如果有)
if [ -d "$TARGET_DIR" ]; then
echo "发现旧版本,清理..."
rm -rf "$TARGET_DIR"
fi
# 创建目录
echo "创建目录: $TARGET_DIR"
mkdir -p "$TARGET_DIR"
# 解压文件
echo "解压文件..."
tar -xzf "$SOURCE_FILE" -C "$TARGET_DIR" --strip-components 1
if [ $? -ne 0 ]; then
echo "错误: 解压失败"
exit 1
fi
# 设置权限
echo "设置执行权限..."
chmod +x "$TARGET_DIR/bin/code-server"
# 验证安装
echo "验证安装..."
if [ -f "$TARGET_DIR/bin/code-server" ] && [ -f "$TARGET_DIR/node" ]; then
echo "✅ VS Code Server 安装成功!"
echo "安装位置: $TARGET_DIR"
echo "文件列表:"
ls -la "$TARGET_DIR/" | head -5
echo "..."
ls -la "$TARGET_DIR/bin/" | head -5
else
echo "❌ 安装失败: 必要的文件缺失"
exit 1
fi
# 可选:清理临时文件
read -p "是否删除临时文件 $SOURCE_FILE? (y/n): " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
rm -f "$SOURCE_FILE"
echo "临时文件已删除"
fi
echo "=== 安装完成 ==="
echo "现在可以重新连接 VS Code Remote SSH 了"
使用方法:
bash
# 给脚本执行权限
chmod +x install_vscode_server.sh
# 运行脚本
./install_vscode_server.sh
5. 一步到位的完整流程
Windows端操作:
powershell
# 1. 下载
$commitId = "6f17636121051a53c88d3e605c491d22af2ba755"
Invoke-WebRequest -Uri "https://update.code.visualstudio.com/commit:${commitId}/server-linux-x64/stable" -OutFile "vscode-server-linux-x64.tar.gz"
# 2. 上传
scp .\vscode-server-linux-x64.tar.gz user@your-server.com:/tmp/
Linux端操作:
bash
# 3. 安装
COMMIT_ID="6f17636121051a53c88d3e605c491d22af2ba755"
mkdir -p ~/.vscode-server/bin/${COMMIT_ID}
tar -xzf /tmp/vscode-server-linux-x64.tar.gz -C ~/.vscode-server/bin/${COMMIT_ID} --strip-components 1
chmod +x ~/.vscode-server/bin/${COMMIT_ID}/bin/code-server
# 4. 验证
ls -la ~/.vscode-server/bin/${COMMIT_ID}/bin/
6. 重新连接测试
- 完全关闭VS Code
- 重新打开VS Code
- 使用Remote-SSH连接服务器
- 应该能正常连接,不再卡在下载界面
7. 常见问题解决
如果还是有问题,检查:
bash
# 检查文件完整性
file ~/.vscode-server/bin/${COMMIT_ID}/node
# 检查权限
ls -la ~/.vscode-server/bin/${COMMIT_ID}/bin/code-server
# 尝试手动运行
~/.vscode-server/bin/${COMMIT_ID}/bin/code-server --version
按照上述流程操作,应该能成功解决下载卡住的问题。
下载VS Code Server后如何操作才能使vscode能够远程连接服务器?
已经有了 vscode-server-linux-x64.tar.gz 文件,现在需要正确解压和安装。以下是完整步骤:
1. 检查当前状态
bash
# 进入目录
cd ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755
# 查看文件
ls -la
# 检查文件类型和大小
file vscode-server-linux-x64.tar.gz
ls -lh vscode-server-linux-x64.tar.gz
2. 解压和安装
方法一:直接解压(推荐)
bash
# 进入目录
cd ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755
# 解压文件(去除顶层目录)
tar -xzf vscode-server-linux-x64.tar.gz --strip-components=1
# 设置执行权限
chmod +x bin/code-server
chmod +x node
方法二:分步解压(更安全)
bash
cd ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755
# 创建临时目录
mkdir temp_extract
# 解压到临时目录
tar -xzf vscode-server-linux-x64.tar.gz -C temp_extract
# 查看解压后的结构
ls -la temp_extract/
# 移动文件到当前目录(去除顶层目录)
mv temp_extract/*/* ./
mv temp_extract/*/.* ./ 2>/dev/null || true
# 删除临时目录
rm -rf temp_extract
# 设置权限
chmod +x bin/code-server node
3. 验证安装结果
bash
# 检查关键文件
ls -la ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/
# 应该看到类似结构:
# bin/ node out/ extensions/ product.json server.sh 等
# 检查可执行文件
file ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/bin/code-server
file ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/node
# 测试运行(可选)
~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/bin/code-server --version
4. 清理压缩包(可选)
bash
# 安装成功后可以删除压缩包节省空间
rm ~/.vscode-server/bin/6f17636121051a53c53c88d3e605c491d22af2ba755/vscode-server-linux-x64.tar.gz
5. 重新连接 VS Code
- 完全关闭所有 VS Code 窗口
- 重新打开 VS Code
- 在 Remote-SSH 中连接你的服务器
- 这次应该能正常连接了
6. 如果还有问题,检查以下内容
检查文件结构:
bash
# 检查完整文件结构
find ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/ -type f -name "*" | head -20
# 检查必要的目录
ls -la ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/bin/
ls -la ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/extensions/
检查权限:
bash
# 确保有执行权限
ls -la ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/bin/code-server
ls -la ~/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755/node
7. 完整的安装脚本
如果手动操作不成功,使用这个脚本:
bash
#!/bin/bash
set -e
VSCODE_DIR="$HOME/.vscode-server/bin/6f17636121051a53c88d3e605c491d22af2ba755"
ARCHIVE="$VSCODE_DIR/vscode-server-linux-x64.tar.gz"
echo "=== 安装 VS Code Server ==="
cd "$VSCODE_DIR"
echo "检查文件..."
if [ ! -f "$ARCHIVE" ]; then
echo "错误: 未找到 vscode-server-linux-x64.tar.gz"
exit 1
fi
echo "文件信息:"
file "$ARCHIVE"
ls -lh "$ARCHIVE"
echo "清理现有文件(保留压缩包)..."
find . -maxdepth 1 ! -name "vscode-server-linux-x64.tar.gz" ! -name "." -exec rm -rf {} + 2>/dev/null || true
echo "解压文件..."
tar -xzf "$ARCHIVE" --strip-components=1
echo "设置权限..."
chmod +x bin/code-server node
echo "验证安装..."
if [ -f "bin/code-server" ] && [ -f "node" ]; then
echo "✅ VS Code Server 安装成功!"
echo "文件结构:"
ls -la
else
echo "❌ 安装失败"
exit 1
fi
echo "=== 安装完成 ==="
echo "现在可以重新连接 VS Code Remote SSH"
使用方法:
bash
chmod +x install_vscode.sh
./install_vscode.sh
关键要点
- 必须使用
--strip-components=1来去除压缩包中的顶层目录 - 必须设置执行权限 给
bin/code-server和node - 完全关闭 VS Code 后重新连接
