Linux 下使用微軟的跨平臺輕量級開發神器 Visual Studio Code

由於 Visual Studio Code 不斷更新,官方最新 v1.32 的 .deb 包已經不能用於 Ubuntu 14.04 直接安裝了。javascript

下載 v1.31 的 deb 包安裝便可:https://code.visualstudio.com/updates/v1_31  (兼容 Ubuntu 14.04,而且支持 Vim 插件php

下載 v1.30 的 deb 包安裝便可:https://code.visualstudio.com/updates/v1_30css

若是要用最新版,在官網下載免安裝版 .tar.gz : https://code.visualstudio.com/#alt-downloadshtml

須要首先安裝 libnss3,java

sudo apt-get install libnss3

直接解壓縮 .tar.gz 到 /opt,設置環境變量便可使用。node

目前已安裝的插件記錄以下: (Version: 1.39)python

===================================================c++

Atom One Dark Themegit

Atom One Light Themesql

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 插件便可)

                                 

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

當前 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.mode": "manual",
    "update.showReleaseNotes": false,

    "gitlens.advanced.messages": {
        "suppressGitVersionWarning": true
    },
    "git.ignoreLegacyWarning": true,

    "code-runner.executorMap": {
        "javascript": "node",
        "python": "python3",
        "html": "/usr/bin/firefox",
        "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",

    "jshint.nodePath": "/usr/lib/node_modules",
    "javascript.updateImportsOnFileMove.enabled": "always",
    "workbench.colorTheme": "Quiet Light",

    "sqltools.useNodeRuntime": true,
    "python.jediPath": "/usr/local/lib/python3.6/site-packages",
    "terminal.integrated.fontFamily": "'Ubuntu mono'",
    "terminal.integrated.fontSize": 16,
    "terminal.integrated.lineHeight": 1.2,
    "terminal.integrated.rendererType": "dom",

    "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",
    ],

    //======================
    // c_cpp_properties.json
    //======================
    // {
    //     "configurations": [
    //         {
    //             "name": "Linux",
    //             "includePath": [
    //                 "${workspaceFolder}/**",
    //                 "/usr/include/",
    //                 "/usr/include/c++/4.8.2"
    //             ],
    //             "defines": [],
    //             "compilerPath": "/usr/bin/clang",
    //             "cStandard": "c99",
    //             "cppStandard": "c++11",
    //             "intelliSenseMode": "clang-x64"
    //         }
    //     ],
    //     "version": 4
    // }
}

 

暫時這些,其它可參考這裏: 

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 爲安裝路徑 (例如 /usr/local/lib/python3.6/site-packages)  -> 再搜索 auto update language server -> 取消 Automatically update the language server -> 回到主界面 Extension -> Disable 掉 Visual Studio IntelliCode.

 

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

 

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

注:這個免費的雜牌軍,好使 ;-p

相關文章
相關標籤/搜索