編輯器

子曰:“工欲善其事,必先利其器。居是邦也,事其大夫之賢者,友其士之仁者。”
———《論語·衛靈公》

1. Visual Studio Code

雖然 tmm 裡面有預裝 code-server(web 網頁伺服器)的容器,但是本節將主要講桌面版的 vscode。

對於本專案的使用者,您之後可以用 apt install code-no-sandbox 來安裝,它將包含兩個啟動圖示。(現在還而沒有打包啦)

除了 code-server 之外,目前比較流行的網頁版 vscode 還有 2 個。

  1. 官方的 vscode.dev
  2. github dev, 假設某倉庫為 github.com/xx/yy, 將 com 修改為 dev:(github.dev/xx/yy)。

1.1. 簡介

vscode 是由微軟(Microsoft)主導開發的一款開源編輯器。

Why is vscode?

有很多人都喜歡 JetBrains 家的 IDE(s), 還有 vscode 的老大哥 Visual Studio
在本節中,我們並不會討論 vscode 相較於其它編輯器或整合開發環境的優劣。

正如《周易·繫辭(上)》中所言:“仁者見之謂之仁,智者見之謂之智。”

對於相同問題,不同使用者站在不同角度有不同的看法。
您如果不喜歡 vscode 的話,那可以跳過本節的內容。


如果您對它感興趣的話,那讓我們帶著愉快的心情,一起去了解 vscode 吧!

1.2. 快捷鍵

瞭解一款軟體的快捷鍵,在某些方面能極大程度地提高您的效率。

以下表格是開發者根據 官方文件 整理出來的。
網上有很多基於官方文件的表格,但是應該很少有人將 windowslinux & macos 三者的 vscode 整合在一起並進行比較吧?

截止 2021-10-23,以下表格會比官方的 pdf 文件多一些內容,之後 vscode 可能會進行更新, 具體內容請以官方文件為主。

對於 LinuxWindows 中相同的快捷鍵,Win 處留空。
對於衝突快捷鍵,或者是預設為空鍵位的地方,使用 🤔️。
例如: ctrl+alt+方向鍵:(Move editor into next/previous group) 與 cinnamon 的切換工作區(switch work space) 快捷鍵衝突。

其實正確的做法,不是看這個表格。
而是先按下 ctrl + K 組合鍵,再按下 ctrl + S, 最後進行搜尋。
不管怎麼說,只要能幫到您,開發者就覺得很開心了。


LinuxWinMacGeneral一般操作
Ctrl+Shift+P, F1⇧⌘P, F1Show Command Palette顯示命令選項板
Ctrl+P⌘PQuick Open, Go to File…快速開啟
Ctrl+Shift+N⇧⌘NNew window/instance新視窗/例項
Ctrl+WCtrl+Shift+W⌘WClose window/instance關閉視窗/例項
Ctrl+,⌘,User Settings使用者設定
Ctrl+K Ctrl+S⌘K ⌘SKeyboard Shortcuts鍵盤快捷鍵

LinuxWinMacBasic editing基礎編輯
Ctrl+X⌘XCut (if empty selection, cut line)剪下(若為空白則剪下整行,若非空則剪下選中內容)
Ctrl+C⌘CCopy (if empty selection, copy line)複製 (若為空白則複製整行,若非空則複製選中內容)
Ctrl+V⌘VPaste貼上
Ctrl+Z⌘ZUndo撤銷(回退到上一步)
Ctrl+Y, Ctrl+Shift+Z⇧⌘ZRedo重做/反撤銷/恢復
Alt+ ↓ / Alt+ ↑⌥↓ / ⌥↑Move line down/up移動行(向下/上)
Shift+Alt+ ↓ / Shift+Alt+ ↑⇧⌥↓ / ⇧⌥↑Copy line down/up複製行(向下/上)
Ctrl+Shift+K⇧⌘KDelete line刪除行
Ctrl+Enter / Ctrl+Shift+Enter⌘Enter / ⇧⌘EnterInsert line below/above插入行(下方/上方)
Ctrl+Shift+\⇧⌘\Jump to matching bracket跳到匹配的括號內
Ctrl+] / Ctrl+[⌘] / ⌘[Indent/outdent line縮排/縮出(取消縮排)行
Home / EndHome / EndGo to beginning/end of line轉到行首/行尾
Ctrl+ Home / Ctrl+ End⌘↑ / ⌘↓Go to beginning/end of file轉到檔案的開頭/結尾處
Ctrl+ ↑ / Ctrl+ ↓⌃PgUp / ⌃PgDnScroll line up/down滾動行(向上/下)
Alt+ PgUp / Alt+ PgDn⌘PgUp /⌘PgDnScroll page up/down滾動頁面(向上/下)
Ctrl+Shift+ [ / Ctrl+Shift+ ]⌥⌘[ / ⌥⌘]Fold/unfold region摺疊/展開(解除摺疊)區域(程式碼塊)
Ctrl+K Ctrl+ [ / Ctrl+K Ctrl+ ]⌘K ⌘[ / ⌘K ⌘]Fold/unfold all subregions摺疊/展開所有子區域
Ctrl+K Ctrl+0 / Ctrl+K Ctrl+J⌘K ⌘0 / ⌘K ⌘JFold/unfold all regions摺疊/展開所有區域
Ctrl+K Ctrl+C⌘K ⌘CAdd line comment新增行註釋
Ctrl+K Ctrl+U⌘K ⌘URemove line comment刪除行註釋
Ctrl+/⌘/Toggle line comment切換行註釋(註釋或取消註釋)
Ctrl+Shift+AShift+Alt+A⇧⌥AToggle block comment切換塊註釋
Alt+Z⌥ZToggle word wrap切換自動換行

LinuxWinMacMulti-cursor and selection多游標與選擇(主要:列塊編輯)
Alt+Click⌥ + clickInsert cursor插入游標
Shift+Alt+↑Ctrl+Alt+↑⌥⌘↑Insert cursor above在上方插入游標
Shift+Alt+↓Ctrl+Alt+↓⌥⌘↓Insert cursor below在下方插入游標
Ctrl+U⌘UUndo last cursor operation撤銷上一次游標操作
Shift+Alt+I⇧⌥IInsert cursor at end of each line selected在選中行的末尾插入游標
Ctrl+L⌘LSelect current line選擇當前行
Ctrl+Shift+L⇧⌘LSelect all occurrences of current selection選擇當前選中項的所有匹配項
Ctrl+F2⌘F2Select all occurrences of current word選擇當前詞的所有匹配項
Shift+Alt+ → / Shift+Alt+ ←⌃⇧⌘→ / ←Expand / shrink selection擴大/縮小選擇
Shift+Alt + drag mouse⇧⌥ + drag mouseColumn (box) selection列塊選擇(先按住 shift+alt,再按住滑鼠左鍵,最後拖拽滑鼠選中指定列塊)
🤔️Ctrl+Shift+Alt+ ↑ / Ctrl+Shift+Alt+ ↓⇧⌥⌘↑ / ↓Column (box) selection up/down列塊選擇(向上/向下)
🤔️Ctrl+Shift+Alt+ ← / Ctrl+Shift+Alt+ →⇧⌥⌘← / →Column (box) selection left/right列塊選擇(左/右)
🤔️Ctrl+Shift+Alt+ PgUp/ Ctrl+Shift+Alt+ PgDn⇧⌥⌘PgUp / PgDnColumn (box) selection page up/down列塊選擇(頁面 上/下 移)
Ctrl+A⌘ASelect all全選

LinuxWinMacSearch and replace搜尋與替換
Ctrl+F⌘FFind查詢
Ctrl+H⌥⌘FReplace替換
F3 / Shift+F3⌘G / ⇧⌘GFind next/previous查詢下一個/上一個
Alt+Enter⌥EnterSelect all occurrences of Find match選擇所有匹配項
Ctrl+D⌘DAdd selection to next Find match選擇下一個匹配項
Ctrl+K Ctrl+D⌘K ⌘DMove last selection to next Find match跳過當前選擇項
Alt+C / Alt+R / Alt+W⌥⌘C/⌥⌘R/⌥⌘WToggle case-sensitive / regex / whole word切換 區分大小寫/正則表示式/全字匹配

LinuxWinMacRich languages editing富文字編輯
Ctrl+Space, Ctrl+I⌃Space, ⌘ITrigger suggestion觸發建議
Ctrl+Shift+Space⇧⌘SpaceTrigger parameter hints觸發引數提示
Ctrl+Shift+IShift+Alt+F⇧⌥FFormat document格式化文件
Ctrl+K Ctrl+F⌘K ⌘FFormat selection格式化所選部分
F12F12Go to Definition轉到定義
Ctrl+Shift+F10Alt+F12⌥F12Peek Definition速覽定義
Ctrl+K F12⌘K F12Open Definition to the side在側邊顯示定義
Ctrl+.⌘.Quick Fix快速修復
Shift+F12⇧F12Show References顯示引用
F2F2Rename Symbol重新命名符號
Ctrl+K Ctrl+X⌘K ⌘XTrim trailing whitespace裁剪尾隨空格
Ctrl+K M⌘K MChange file language更改檔案語言

LinuxWinMacNavigation導航
Ctrl+T⌘TShow all Symbols顯示所有符號
Ctrl+G⌃GGo to Line...轉到指定行...
Ctrl+P⌘PGo to File...轉到檔案...
Ctrl+Shift+O⇧⌘OGo to Symbol...轉到符號...
Ctrl+Shift+M⇧⌘MShow Problems panel顯示問題面板
F8/Shift+F8F8 / ⇧F8Go to next/previous error or warning轉到下一個/上一個錯誤或警告
Ctrl+Shift+Tab⌃⇧TabNavigate editor group history在編輯器組(視窗)歷史記錄間進行導航(先按住 Ctrl+Shift,再按 tab 切換)
Ctrl+Alt+ -/Ctrl+Shift+ -Alt+ ← / Alt+ →⌃- / ⌃⇧-Go back/forward後退/前進
Ctrl+M⌃⇧MToggle Tab moves focus切換 tab 鍵移動焦點(先按下 ⌃⇧M / Ctrl+M,再多按幾次 tab 鍵 移動焦點 )
Ctrl+Shift+B⌃⇧BRun build task執行生成(構建)任務
🤔️Run task執行任務,預設為空,您可以自定義為 ⌃⌘B

LinuxWinMacEditor management編輯器管理
Ctrl+WCtrl+F4, Ctrl+W⌘WClose editor(file/tag)關閉編輯器(檔案/標籤頁)
Ctrl+K F⌘K FClose folder關閉資料夾
Ctrl+\⌘\Split editor拆分編輯器視窗
Ctrl+1 / Ctrl+2 / Ctrl+3⌘1 / ⌘2 / ⌘3Focus into 1st, 2nd, 3rd editor group聚焦(切換)到第 1、第 2 或 第 3 個編輯組(視窗)
Ctrl+K Ctrl+← / Ctrl+K Ctrl+→⌘K ⌘← / ⌘K ⌘→Focus into previous/next editor group切換到上一個/下一個視窗
Ctrl+Shift+PgUp / Ctrl+Shift+PgDn⌘K ⇧⌘← / ⌘K ⇧⌘→Move editor left/right向左/右移動編輯器
Ctrl+K ← / Ctrl+K →⌘K ← / ⌘K →Move active editor group向左/右移動正在使用(活動中)的視窗
Ctrl+PgUp / Ctrl+PgDn⌥⌘←/⌥⌘→Focus into previous/next editor切換到上一個/下一個編輯器
🤔️Ctrl+Alt+ → / Ctrl+Alt+ ←⌃⌘→/⌃⌘←Move editor into next/previous group將編輯器移動到下一組/上一組
Alt+F4⌘QQuit vscode退出 vscode

LinuxWinMacFile management檔案管理
Ctrl+N⌘NNew file新檔案
Ctrl+O⌘OOpen file...開啟檔案...
Ctrl+S⌘SSave儲存
Ctrl+Shift+S⇧⌘SSave as...另存為...
🤔️Ctrl+K S⌥⌘SSave all全部儲存
Ctrl+WCtrl+F4⌘WClose關閉
Ctrl+K Ctrl+W⌘K ⌘WClose all全部關閉
Ctrl+Shift+T⇧⌘TReopen closed editor重新開啟關閉的編輯器
Ctrl+K Enter⌘K EnterKeep preview mode editor open保持預覽模式下的編輯器處於開啟狀態
Ctrl+Tab / Ctrl+Shift+Tab⌃Tab / ⌃⇧TabOpen next / previous開啟下一個/上一個
Ctrl+K P⌘K PCopy path of active file複製活動檔案的路徑
Ctrl+K R⌘K RReveal active file in File Explorer在檔案管理器中顯示活動檔案
Ctrl+K O⌘K OShow active file in new window/instance在新視窗/例項中顯示活動檔案
Space, EnterSpaceOpen file in explorer先按下 ⇧⌘E 開啟資源管理器,然後按方向鍵選擇檔案,最後按下空格開啟檔案
Ctrl+Enter⌃EnterOpen file to the side在側邊開啟檔案
F2EnterRename file in explorer在資源管理器中重新命名檔案
Delete⌘Backspacedelete file in explorer在資源管理器中刪除檔案

LinuxWinMacDisplay顯示
F11⌃⌘FToggle full screen切換全屏
Shift+Alt+0⌥⌘0Toggle editor layout (horizontal/vertical)切換編輯器佈局(水平/垂直)
Ctrl+ = / Ctrl+ -⌘= / ⇧⌘-Zoom in/out放大/縮小
Ctrl+B⌘BToggle Sidebar visibility切換側邊欄的可見性(開啟/關閉側邊欄)
Ctrl+Shift+E⇧⌘EShow Explorer / Toggle focus顯示資源管理器/切換焦點
Ctrl+Shift+F⇧⌘FShow Search顯示搜尋
Ctrl+Shift+G⌃⇧GShow Source Control顯示原始碼控制
Ctrl+Shift+D⇧⌘DShow Debug顯示除錯
Ctrl+Shift+X⇧⌘XShow Extensions顯示擴充套件
Ctrl+Shift+H⇧⌘HReplace in files替換檔案中的內容
Ctrl+Shift+J⇧⌘JToggle Search details切換搜尋詳情
Ctrl+K Ctrl+HCtrl+Shift+U⇧⌘UShow Output panel顯示輸出面板
Ctrl+Shift+V⇧⌘VOpen Markdown preview開啟 markdown 預覽
Ctrl+K V⌘K VOpen Markdown preview to the side在側邊開啟 markdown 預覽
Ctrl+K Z⌘K ZZen Mode (Esc to exit)禪模式(按 Esc 退出)
Ctrl+Shift+C⇧⌘COpen new command prompt/terminal開啟新的命令提示符/終端

LinuxWinMacDebug除錯
F9F9Toggle breakpoint切換斷點
F5F5Start/Continue開始/繼續
F11 / Shift+F11F11 / ⇧F11Step into/ out單步除錯:進入/跳出
F10F10Step over單步跳過
Shift+F5⇧F5Stop停止
Ctrl+K Ctrl+I⌘K ⌘IShow hover顯示懸停

LinuxWinMacIntegrated terminal整合終端
Ctrl+`⌃`Show integrated terminal顯示整合(內建)終端
Ctrl+Shift+`⌃⇧`Create new terminal建立新的終端
Ctrl+CInterrupt foreground process中斷執行中的前臺程序
Ctrl+Shift+CCtrl+C⌘CCopy selection先用滑鼠選中,再按下“指定按鍵”進行復制
Ctrl+Shift+VCtrl+V⌘VPaste into active terminal貼上
Ctrl+Shift+ ↑ / Ctrl+Shift+ ↓Ctrl+Alt+PgUp / Ctrl+Alt+PgDn⌘↑ / ↓Scroll up/down向上/向下滾動(行)
Shift+ PgUp / Shift+ PgDnPgUp / PgDnScroll page up/down向上/向下滾動(頁)
Shift+ Home / Shift+ EndCtrl+ Home / Ctrl+ End⌘Home / EndScroll to top/bottom滾動到頂部/底部
Ctrl+Shift+5⌘\ , ⌃⇧5Split terminal拆分終端
Ctrl+PgUp / Ctrl+PgDn⇧⌘[ / ]Focus previous/next terminal聚焦(切換)上/下 一個 終端
Alt+ ↑ / Alt+ ↓⌥⌘↑ / ↓Focus previous/next terminal in group在終端組中切換 上/下 一個終端
Ctrl+Shift+ ← / Ctrl+Shift+ →🤔️⌃⌘← / →Resize terminal left/right調整終端大小(左/右)
🤔️⌃⌘↑ / ↓Resize terminal up/down調整終端大小(上/下)