zoukankan      html  css  js  c++  java
  • Linux 下使用微软的跨平台轻量级开发神器 Visual Studio Code

    因为 Visual Studio Code 不断更新,官方最新 v1.32 的 .deb 包已经不能用于 Ubuntu 14.04 直接安装了。

    下载 v1.31 的 deb 包安装即可:https://code.visualstudio.com/updates/v1_31  (兼容 Ubuntu 14.04,并且支持 Vim 插件

    下载 v1.30 的 deb 包安装即可:https://code.visualstudio.com/updates/v1_30

    如果要用最新版,在官网下载免安装版 .tar.gz : https://code.visualstudio.com/#alt-downloads

    需要首先安装 libnss3,

    sudo apt-get install libnss3

    直接解压缩 .tar.gz 到 /opt,设置环境变量即可使用。

     above is obsolete 

    目前已安装的插件记录如下: (Version: 1.39)

    ===================================================

    Atom One Dark Theme

    Atom One Light Theme

    Dracula At Night   (比较好的黑色背景)

    Dracula Theme

    Auto Close Tag (不太有用)

    Auto Rename Tag     (HTML tag 的配对更改)

    Beautify     (支持 HTML,JavaScript,CSS, JSON 的格式化,选中区域按 F1,或直接按 F1 对全文进行格式整理)

    Bracket Pair Colorizer     (只在黑屏背景表现不错)

    C/C++   (C/C++ 的自动补全)

    Code Runner    (ctrl + alt + n 运行,ctrl + alt + m 停止)

    HTML Boilerplate    (HTML5 的简易模板)

    jshint   (JavaScript 的自动补全)

    Path intellisense   (路径自动补全)

    SQLTools   (对常用数据库的可视化操作,对 SQLite 支持不太好,见下述 X9 问题及解决方案)

    SQLite (对 SQLite 支持很好)

    Vim   (提供的 vim 功能)

    GitLens  (适合团队开发,个人开发不建议使用,硬盘读写太厉害……老旧机器吃不消)

    Git History  (和 GitLens 功能类似)

    ESLint  (ECMA Script lint,jshint 已有类似功能,并且效果更佳)

    Path Autocomplete  (路径自动补全,和 Path intellisense 功能类似)

    Python Extension Pack (包括如下)

        - Django  (不太有用,Python 扩展已经支持 Django 的补全)

        - Jinja  (不太有用,Jinja2 模板的代码着色工具)

        - MagicPython  (不太有用,Python 的一个语法加亮工具)

        - Visual Studio IntelliCode (如果能上网,并且如果 jedi 不好使,可以试一下这个)

      - Python  (如果 jedi 可用,推荐单独安装这一个,Python 的自动补全,也支持 Django 的自动补全,个人感觉比 IntelliCode 静态分析做的好一些……)

    REST Client  (REST Client for Visual Studio Code

    vscode-cudacpp   (CUDA C++ language support for Visual Studio Code)

    Upper Case SQL

    JS & CSS Minifier (Javascript 和 CSS 的压缩工具,安装之后状态栏左下角会有 X Minify 标志,(首先,点击即可压缩当前的 xxx.css 为 xxx.min.css (此文件自动生成),反之,如果要从 min 格式到正常格式,使用 上述的 Beauty 插件即可)

    Docker

                                     

    ===================================================

    当前 settings.json 配置为 (需根据实际情况修订),

    {
        "editor.fontFamily": "'ubuntu mono', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
        "editor.fontSize": 17,
        "editor.rulers": [ 120 ],
        "editor.minimap.enabled": false,
        "editor.suggestSelection": "first",
        "editor.snippetSuggestions": "none",
    
        "files.autoSave": "off",
    
        "update.enableWindowsBackgroundUpdates": false,
        "update.showReleaseNotes": false,
    
        "code-runner.executorMap": {
            "javascript": "node",
            "python": "python3",
            "html": "/usr/bin/firefox",
            // "html": "/usr/bin/google-chrome",
            "c": "cd $dir && clang $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            // "php": "/usr/bin/php",
            // "perl": "/usr/bin/perl",
            // "ruby": "/usr/bin/ruby",
            // "go": "go run",
            // "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
        },
        "code-runner.clearPreviousOutput": true,
        "code-runner.saveFileBeforeRun": true,
        "code-runner.showExecutionMessage": false,
    
        "C_Cpp.updateChannel": "Insiders",
        // "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue",
        // "files.associations": {
        //     "*.html": "html"
        // },
        // "python.autoUpdateLanguageServer": false,
    
        "jshint.nodePath": "/usr/local/node-v10.16.0-linux-x64/lib/node_modules",
        "workbench.startupEditor": "newUntitledFile",
        "extensions.ignoreRecommendations": true,
        "python.jediPath": "/usr/local/lib/python3.6/dist-packages",
    
        "sqltools.useNodeRuntime": true,
        "python.autoUpdateLanguageServer": false,
        "terminal.integrated.fontFamily": "'ubuntu mono'",
        "terminal.integrated.fontSize": 17,
        "debug.console.fontFamily": "'ubuntu mono'",
        "debug.console.fontSize": 17,
    
        "python.linting.pylintArgs": [
            "--load-plugins=pylint_django",
            "--disable=all",
            "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",
        ],
        "extensions.autoUpdate": false,
    }

    暂时这些,其它可参考这里: 

    https://blog.csdn.net/shenxianhui1995/article/details/81604818

    https://blog.csdn.net/win7583362/article/details/79315055/

    X1. 插件的配置

    File -> Preferences -> Settings -> User Settings -> Extensions -> Run Code configurations -> Executor Map (Edit in settings.json)

    例如,

    {
        "workbench.colorTheme": "Default Light+",
        "editor.fontFamily": "'ubuntu mono', 'Droid Sans Mono', 'monospace', monospace, 'Droid Sans Fallback'",
        "editor.fontSize": 18,
        "editor.minimap.enabled": false,
        "editor.rulers": [
            120
        ],
        "files.autoSave": "off",
        "update.enableWindowsBackgroundUpdates": false,
        "update.mode": "manual",
        "update.showReleaseNotes": false,
    
        "code-runner.executorMap": {
            "javascript": "node",
            // "php": "C:\php\php.exe",
            "python": "python3",
            // "perl": "perl",
            // "ruby": "C:\Ruby23-x64\bin\ruby.exe",
            // "go": "go run",
            "html": "/usr/bin/firefox",
            // "java": "cd $dir && javac $fileName && java $fileNameWithoutExt",
            "c": "cd $dir && clang $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
            "cpp": "cd $dir && clang++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
        },
        "code-runner.clearPreviousOutput": true,
        "code-runner.saveFileBeforeRun": true,
    }

    注意:调试 html 时,先手动把 firefox 打开,然后在 vscode 里可多次 run html 文件,否则如果依赖 vscode 打开 firefox,则下一次 run 同样的文件,会显示 code is already running 而不会更新 firefox 内容。

    X2. 增加 Editor ruler

    File -> Preferences -> Settings -> 搜索 ruler -> Editor:Rulers (Edit in settings.json),加入 如下配置(注意,可配置多条 ruler 线,如下配置两条),

    "editor.rulers":[80, 120],

    X3. 设置 Jedi 为 Python 的默认补全引擎

    安装 Python Extension Pack 之后,Python 的默认补全引擎是 Microsoft Python Analysis Engine, 每次启动 vscode 都会下载或更新,并且导致下载更新阶段 Python 补全不能用。所以这里直接禁掉默认引擎,而使用 Jedi 进行补全。

    $ sudo pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple/ jedi

    设置方法: File -> Preferences -> Settings -> 搜索 jedi ->  勾选 Jedi Enable -> 设置 Jedi Path 为安装路径 (例如 (注意,有时可能要取消这个设置……vscode不补全的时候……bug???) /usr/local/lib/python3.6/site-packages)  -> 再搜索 auto update language server -> 取消 Automatically update the language server -> 回到主界面 Extension -> Disable 掉 Visual Studio IntelliCode.

    注意1:Jedi 要配合 Python 扩展才能使用,settings.json 可做如下设置,

    "python.languageServer": "Jedi",
    

     注意2:如果 Python + Jedi 不好使,可以试一下 Python + Pylance 的组合。

    X4. jshint 的安装配置

    首先通过 Terminal 安装 jshint library,

    $ sudo npm install -g jshint

    安装完成后,jshint 会在 /usr/bin/jshint,而库文件在 /usr/lib/node_modules 下的 jshint.

    通过 VScode 安装 jshint 插件,然后在settings.json 中设置,

        "jshint.nodePath" : "/usr/lib/node_modules",

    这样就能通过 jshint 实时检查 javascript 的 warning ,error 等信息了。

    X5. SQLTools 配置

    简单使用 SQLite3 时的简单配置,具体使用方法可见: https://vscode-sqltools.mteixeira.dev/features/sessions-and-multiple-connections

     "sqltools.useNodeRuntime": true,

    X6. 离线安装插件

    对于不能联网的计算机,可以离线安装扩展,

    在  https://marketplace.visualstudio.com/vscode 搜索需要的插件,例如 SQLTools,在插件展示页面找到 Download Extension,下载例如 mtxr.sqltools-0.21.0.vsix,然后可以直接安装,

    $ sudo code --install-extension <path-to-vsix>

    使用 $ code --help 查看更多可用选项。

    X7. 解决 Pylint 对 Django 的误报问题

    安装 pylint-django,

    $ sudo pip3 install pylint-django

    并添加配置,

    
    
        "python.linting.pylintArgs": [
            "--load-plugins=pylint_django",
            "--disable=all",
            "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode",
        ],

     详情可参见官方文档 https://code.visualstudio.com/docs/python/linting

    X8. 常用快捷键

    Ctrl + Shift + p      : 打开 Command Palette (然后可以使用相关 Extension 的命令,比如 SQLite xxx)

    Ctrl + `                  : 打开 Terminal

    F5                         : 开始 Debugging 模式运行

    Shift + F5              : 停止 Debugging 运行

    Ctrl + Shift + F5    : 重新开始 Debugging 运行 

    X9. SQLTools 插件可能遇到的问题

    (1)创建 sqlite 连接时,提示需要安装 sqlite3@4.0.8,但是点击提示框的 install,安装失败。

      解决方法:先保存新建的连接,然后点击连接,这时会再次弹出 sqlite3@4.0.8 的安装提示,这时再点击 install 即可安装成功。

    (2)创建 sqlite 连接时,选择当前工程目录的数据库文件,例如 db.sqlite3,提示 SQLITE_CANTOPEN: unable to open database file

      解决方法:将当前工程目录的数据库文件改为相对路径即可,即 ./db.sqlite3

    X10. 由于 VScode 升级引起的 HTML Mirror Cursor 的问题

     打开 Settings,输入 html.mirror,然后取消 HTML: Mirror Cursor On Matching Tag 即可。

    X11. 常用快捷键定义

    https://www.cnblogs.com/gaowengang/p/11372309.html

    --------------------------------------------

    注:这个免费的杂牌军,好使 ;-p

  • 相关阅读:
    (转载)linux 常用命令
    视图view
    Mysql增删改查
    mysql最基础命令
    mysql的基本操作
    (转载)RHEL7(RedHat 7)本地源的配置
    (转载)Linux之虚拟机 rehl7的ip
    js 基本
    java Servlet
    java Tttp协议和Tomcat
  • 原文地址:https://www.cnblogs.com/gaowengang/p/10589534.html
Copyright © 2011-2022 走看看