插件窝 干货文章 在Linux上使用Visual Studio Code进行后端开发的推荐配置

在Linux上使用Visual Studio Code进行后端开发的推荐配置

配置 true Python 扩展 578    来源:    2025-04-16

Linux上使用VS Code进行后端开发的推荐配置

基础安装

  1. 安装VS Code

    # Ubuntu/Debian
    sudo apt update && sudo apt install code
    
    # Fedora/RHEL
    sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
    sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
    sudo dnf install code
    
  2. 安装必要工具链

    # 通用开发工具
    sudo apt install build-essential git curl wget
    

语言特定配置

Python开发

  1. 扩展

    • Python (Microsoft)
    • Pylance
    • Jupyter (可选)
  2. 配置

    {
     "python.pythonPath": "/path/to/your/python",
     "python.linting.enabled": true,
     "python.linting.pylintEnabled": true,
     "python.formatting.provider": "black",
     "python.analysis.typeCheckingMode": "basic"
    }
    

Java开发

  1. 扩展

    • Java Extension Pack (Microsoft)
    • Maven for Java
    • Gradle for Java
  2. 配置

    {
     "java.home": "/path/to/jdk",
     "java.jdt.ls.vmargs": "-Xmx2G",
     "java.configuration.updateBuildConfiguration": "automatic"
    }
    

Node.js/JavaScript开发

  1. 扩展

    • ESLint
    • Prettier - Code formatter
    • npm Intellisense
  2. 配置

    {
     "eslint.validate": ["javascript", "javascriptreact", "typescript", "typescriptreact"],
     "prettier.singleQuote": true,
     "javascript.updateImportsOnFileMove.enabled": "always"
    }
    

Go开发

  1. 扩展

    • Go (Go Team at Google)
  2. 配置

    {
     "go.gopath": "/path/to/your/gopath",
     "go.useLanguageServer": true,
     "go.lintTool": "golangci-lint"
    }
    

通用开发工具

  1. 推荐扩展

    • Docker
    • Remote - SSH (远程开发)
    • GitLens
    • REST Client (API测试)
    • Database Client (数据库管理)
    • YAML/JSON工具
    • Markdown All in One
  2. 终端配置

    • 使用集成终端 (Ctrl+`)
    • 推荐配置zsh+oh-my-zsh或fish shell
    • 安装tmux或screen用于会话管理

性能优化

  1. 配置

    {
     "files.exclude": {
       "**/.git": true,
       "**/.svn": true,
       "**/.hg": true,
       "**/CVS": true,
       "**/.DS_Store": true,
       "**/node_modules": true,
       "**/__pycache__": true
     },
     "search.exclude": {
       "**/node_modules": true,
       "**/bower_components": true,
       "**/*.code-search": true
     },
     "editor.fontSize": 14,
     "editor.tabSize": 2,
     "editor.renderWhitespace": "selection",
     "editor.minimap.enabled": false
    }
    
  2. 硬件加速

    code --disable-gpu
    

远程开发

  1. 使用Remote-SSH

    • 配置SSH密钥
    • 安装Remote-SSH扩展
    • 连接远程服务器进行开发
  2. 使用Dev Containers

    • 安装Docker
    • 安装Remote-Containers扩展
    • 使用容器化开发环境

调试配置

  1. 通用调试配置

    • 安装Debugger for Chrome/Edge (前端调试)
    • 配置launch.json文件
  2. 示例Python调试配置

    {
     "version": "0.2.0",
     "configurations": [
       {
         "name": "Python: Current File",
         "type": "python",
         "request": "launch",
         "program": "${file}",
         "console": "integratedTerminal"
       }
     ]
    }
    

版本控制

  1. Git集成

    • 安装Git
    • 配置用户信息: bash git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
    • 使用VS Code内置Git功能或GitLens扩展
  2. 推荐配置

    {
     "git.enableSmartCommit": true,
     "git.confirmSync": false,
     "git.autofetch": true
    }
    

快捷键自定义

  1. 常用快捷键

    • Ctrl+P: 快速文件导航
    • Ctrl+Shift+P: 命令面板
    • F12: 跳转到定义
    • Ctrl+Shift+F: 全局搜索
    • Ctrl+Shift+E: 资源管理器
  2. 自定义快捷键

    {
     "key": "ctrl+shift+b",
     "command": "workbench.action.tasks.build",
     "when": "editorTextFocus"
    }
    

主题和外观

  1. 推荐主题

    • One Dark Pro
    • Material Theme
    • GitHub Theme
  2. 图标主题

    • Material Icon Theme
    • vscode-icons
  3. 字体推荐

    • Fira Code (带连字)
    • JetBrains Mono
    • Cascadia Code

这些配置应该能为您在Linux上使用VS Code进行后端开发提供一个强大的基础环境。根据您的具体技术栈和偏好,可以进一步调整和扩展这些配置。