VSCode 的 Vim 配置和快捷鍵配置

Koshkaaa發表於2024-04-13

keybinds.json

// Place your key bindings in this file to override the defaultsauto[]
[
  // 以前配置的上下左右移動按鍵
  {
    "key": "alt+j",
    "command": "cursorLeft",
    "when": "textInputFocus"
  },
  {
    "key": "alt+k",
    "command": "cursorDown",
    "when": "textInputFocus"
  },
  {
    "key": "alt+l",
    "command": "cursorRight",
    "when": "textInputFocus"
  },
  {
    "key": "alt+i",
    "command": "cursorUp",
    "when": "textInputFocus"
  },
  // 切換到檔案瀏覽器,可以在任何位置
  {
    "key": "ctrl+;",
    "command": "workbench.view.explorer",
    "when": "viewContainer.workbench.view.explorer.enabled"
  },
  // 切換到程式碼編輯區,不論在任何位置
  {
    "key": "ctrl+'",
    "command": "workbench.action.focusFirstEditorGroup"
  },
  // 切換到terminal終端
  {
    "key": "ctrl+,",
    "command": "workbench.action.terminal.toggleTerminal",
    "when": "terminal.active"
  },
  // 開啟一個新的terminal
  {
    "key": "ctrl+shift+,",
    "command": "workbench.action.terminal.new",
    "when": "terminalProcessSupported || terminalWebExtensionContributedProfile"
  },
  // 在資料夾資源管理器中新建一個檔案
  {
    "key": "a",
    "command": "explorer.newFile",
    "when": "filesExplorerFocus && !inputFocus"
  },
  // 在檔案資源管理器裡面建立一個資料夾
  {
    "key": "shift+a",
    "command": "explorer.newFolder",
    "when": "filesExplorerFocus && !inputFocus"
  },
  // 在檔案資源管理器裡面重應名當前檔案或資料夾
  {
    "key": "r",
    "command": "renameFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
  },
  // 在檔案資源管理器中刪除檔案
  {
    "key": "d",
    "command": "deleteFile",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
  },
  // 複製當前檔案
  {
    "key": "y",
    "command": "filesExplorer.copy",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
  },
  // 黏貼當前檔案
  {
    "key": "p",
    "command": "filesExplorer.paste",
    "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
  },
  // 放大editor區域
  {
    "key": "ctrl+m",
    "command": "workbench.action.maximizeEditor"
  },
  // 使用code runner執行程式碼
  {
    "key": "ctrl+r",
    "command": "code-runner.run"
  }
]

settings.json

{
  "[vue]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[typescript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "editor.formatOnSave": true,
  "editor.lineNumbers": "relative",
  "[javascript]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  // -------------------------------------------------
  "vim.leader": "<space>",
  "vim.useSystemClipboard": true,
  "vim.hlsearch": true,
  "vim.highlightedyank.enable": true,
  "vim.foldfix": true,
  "vim.easymotion": true,
  "vim.incsearch": true,
  "vim.useCtrlKeys": true,
  "vim.surround": true,
  "vim.sneak": true,
  "vim.sneakUseIgnorecaseAndSmartcase": true,
  "vim.normalModeKeyBindingsNonRecursive": [
    // Go to start or end of line---------------------------
    {
      "before": ["H"],
      "after": ["^"]
    },
    {
      "before": ["L"],
      "after": ["$"]
    },
    // ----------------------------------------------------
    // Jump to change
    {
      "before": ["[", "c"],
      "commands": ["workbench.action.editor.previousChange"]
    },
    {
      "before": ["]", "c"],
      "commands": ["workbench.action.editor.nextChange"]
    },
    // Code actions
    {
      "before": ["<leader>", "s", "a"],
      "commands": ["editor.action.sourceAction"]
    },
    {
      "before": ["<space>", "r", "r"],
      "commands": [
        // "extension.runScript"
        // "autojspro.run"
        "code-runner.run"
      ]
    },
    // Quick fix
    {
      "before": ["<leader>", "q", "f"],
      "commands": ["editor.action.quickFix"]
    },
    // 重用名變數
    {
      "before": ["<leader>", "r", "n"],
      "commands": ["editor.action.rename"]
    },
    // Format 格式化當前檔案
    {
      "before": ["<leader>", "f", "m"],
      "commands": ["editor.action.formatDocument"]
    },
    // go===================================================
    // go to  References
    {
      "before": ["g", "r"],
      "commands": ["editor.action.goToReferences"]
    },
    // ===================================================
    // new===================================================
    // 新建資料夾,在編輯器的區域
    {
      "before": ["<Leader>", "n", "d"],
      "commands": ["explorer.newFolder"]
    },
    // 新建檔案,新建檔案的位置取決於,檔案資源管理器所在的位置
    {
      "before": ["<Leader>", "n", "f"],
      "commands": ["explorer.newFile"]
    },
    // =====================================================
    // open========================================================
    // 開啟檔案資源管理器,游標會聚焦到檔案資源管理器的視窗
    {
      "before": ["<leader>", "o", "e"],
      "commands": ["workbench.view.explorer"]
    },
    // open search bar
    {
      "before": ["<leader>", "o", "s"],
      "commands": ["workbench.action.quickOpen"]
    },
    // 進入到terminal
    {
      "before": ["<leader>", "o", "t"],
      "commands": ["workbench.action.terminal.toggleTerminal"]
    },
    // 新建一個terminal終端
    {
      "before": ["<leader>", "o", "T"],
      "commands": ["workbench.action.terminal.new"]
    },
    // 隱藏和開啟terminal
    {
      "before": ["<leader>", "o", "t"],
      "commands": ["workbench.action.togglePanel"]
    },
    // ================================================
    // find char in all files(fing in all files)
    {
      "before": ["<leader>", "f", "a"],
      "commands": ["workbench.action.findInFiles"]
    },
    // ===============================================
    // 移動==============================================================================
    // 左右移動標籤頁------------------------------------------------
    {
      "before": ["<leader>", "h"],
      "commands": ["workbench.action.navigateLeft"]
    },
    {
      "before": ["<leader>", "l"],
      "commands": ["workbench.action.navigateRight"]
    },
    // 移動下一個編輯器標籤
    {
      "before": ["J"],
      "commands": ["workbench.action.nextEditor"]
    },
    // 移動到上一個編輯器標籤
    {
      "before": ["K"],
      "commands": ["workbench.action.previousEditor"]
    },
    // 左右移動標籤頁---------------------------------------------------------------
    {
      "before": ["<space>", "'"],
      "commands": ["workbench.action.maximizeEditor"]
    },
    // 儲存當前檔案---------------------------------------------------------------
    {
      "before": ["<space>", "s"],
      "commands": ["workbench.action.files.save"]
    },
    {
      "before": ["g", "b"],
      "commands": ["workbench.action.navigateBack"],
      "when": "canNavigateBack"
    },
    // workbench.action.closeActiveEditor
    {
      "before": ["<space>", "w", "c"],
      "commands": ["workbench.action.closeActiveEditor"]
    },
    //workbench.action.closeAllEditors
    {
      "before": ["<space>", "w", "a"],
      "commands": ["workbench.action.closeAllEditors"]
    },
 
    {
      "before": ["<space>", "q", "f"],
      "commands": ["editor.action.quickFix"]
    }
  ],
  "vim.insertModeKeyBindings": [
    // 退出插入模式
    {
      "before": ["j", "k"],
      "after": ["<Esc>"]
    }
  ],
  "vim.visualModeKeyBindingsNonRecursive": [
    // 移動到非空字元的行首
    {
      "before": ["H"],
      "after": ["^"]
    },
    // 移動到非空字元的行尾
    {
      "before": ["L"],
      "after": ["$"]
    }
  ],
  "vim.digraphs": {},
  "vim.commandLineModeKeyBindings": [],
  "vim.commandLineModeKeyBindingsNonRecursive": [],
  "[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  },
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features"
  },
  // ====================================================================
  "EnglishChineseDictionary.enableHover": true,
  "security.workspace.trust.untrustedFiles": "open",
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "liveServer.settings.donotShowInfoMsg": true,
  "typescript.updateImportsOnFileMove.enabled": "always",
  "javascript.updateImportsOnFileMove.enabled": "always",
  "workbench.colorTheme": "Monokai",
  "[python]": {
    "editor.defaultFormatter": "ms-python.python"
  },
  // 忽略排除的檔案
  "files.exclude": {
    "**/.git": true,
    "**/.svn": true,
    "**/.hg": true,
    "**/CVS": true,
    "**/.DS_Store": true,
    "**/Thumbs.db": true,
    "**/__pycache__": true, // python 生產的cache檔案
    "**/.idea": true
  }
}

相關文章