首页 > 其他分享 >vscode-vim键盘操作配置

vscode-vim键盘操作配置

时间:2023-03-14 14:56:06浏览次数:46  
标签:key ctrl vscode vim 键盘 command && action

vscode(win) + vim 键盘操作配置

参考了知乎博主 云崖君vscode + vim 全键盘操作高效搭配方案, 仅用以记录个人使用配置, 内容较为简略。 配置文件如下详见后续说明。

指令总览

ctrl + g c : 显示命令面板
ctrl + g s : 打开设置页面
ctrl + g p : 工作空间文件快速打开
ctrl + g m : 打开一个目录
ctrl + g f : 打开一个文件
ctrl + g h : 打开最近记录
ctrl + g n : 新建vscode实例
ctrl + g q : 关闭vscode示例

ctrl + f n : 新建文件
ctrl + f o : 打开文件
ctrl + f e : 另存为文件
ctrl + f s : 保存文件
ctrl + f w : 保存所有文件
ctrl + f q : 关闭文件
ctrl + f a : 关闭所有文件

ctrl + n [ : 切换侧边栏显示状态
ctrl + n 1 : 显示文件资源管理器
ctrl + n 2 : 显示全局搜索
ctrl + n 3 : 显示版本控制
ctrl + n 4 : 显示debug
ctrl + n 5 : 显示插件商店
ctrl + n 6 : 显示TODO Tree
ctrl + n 7 : 显示Bookmark
​ctrl + n 7 : 显示cnblog account

ctrl + p [ : 切换面板显示状态
ctrl + p 1 : 显示问题
ctrl + p 2 : 显示输出
ctrl + p 3 : 显示终端
ctrl + p 4 : 显示调试控制台

ctrl + q :关闭当前选项卡或分屏
ctrl + e :聚焦在第一个选项卡中
ctrl + , :切换到上一个选项卡
ctrl + . :切换到下一个选项卡
​
ctrl + w s :拆分一个上下分屏
ctrl + w v :拆分一个左右分屏
​
ctrl + w k :将光标向上移动1屏
ctrl + w j :将光标向下移动1屏
​
ctrl + w h :将光标向左移动1屏
ctrl + w l :将光标向右移动1屏

ctrl + h : 触发帮助提示
ctrl + j : 触发参数提示
ctrl + k : 触发建议提示
ctrl + n : 移动到下一个建议
ctrl + p : 移动到上一个建议
tab      : 选择下一个建议
enter    : 选择当前建议

zz : 切换代码折叠(原生vim的zz不是切换折叠)
g[ : 跳转到上一个问题
g] : 跳转到下一个问题

ctrl + alt + l : 格式化代码(个人习惯)
 ​
ctrl + = : 放大字体
ctrl + - : 缩小字体

ctrl + [ : 快速缩进
ctrl + ] : 快速退格

// 编辑模式下生效
alt + j  : 光标上移
alt + k  : 光标下移
alt + h  : 光标左移
alt + l  : 光标右移

// 内嵌指令
<leader><leader>s<char> : 快速定位

ds<existing>            : 删除符号
cs<existing><desired>   :替换符号

gcc :行注释
gCC :块注释

gd : 跳转到函数定义或引用处,搭配 ctrl+i/ctrl+o 查看源码很方便
gh : 触发帮助提示
gb : 开启多光标模式,选中和当前单词相同的单词

基础配置项 (settings.json)

代码控制区域热键方案

zz : 切换代码折叠(原生vim的zz不是切换折叠)

g[ : 跳转到上一个问题
g] : 跳转到下一个问题
    /* setting.json */
    // 绑定vim前导键
    "vim.leader": "<space>",
    // 启用easymotion插件
    "vim.easymotion": true,
    // 启用系统粘贴板作为vim寄存器
    "vim.useSystemClipboard": true,
    // 由vim接管ctrl+any的按键,而不是vscode
    "vim.useCtrlKeys": true,
    // 突出显示与当前搜索匹配的所有文本
    "vim.hlsearch": true,
    // 普通模式下的非递归按键绑定
    "vim.normalModeKeyBindingsNonRecursive": [
        { // toggle Fold
        "before": [
            "z",
            "z",
        ],
        "commands": [
            "editor.toggleFold"
        ]
        },
        { // previous problem 
        "before": [
            "g",
            "[",
        ],
        "commands": [
            "editor.action.marker.prevInFiles"
        ]
        },
        { // next problem 
        "before": [
            "g",
            "]",
        ],
        "commands": [
            "editor.action.marker.nextInFiles"
        ]
        },
    ],
    // 插入模式下的非递归按键绑定
    "vim.insertModeKeyBindings": [],
    // 命令模式下的非递归按键绑定
    "vim.commandLineModeKeyBindingsNonRecursive": [],
    // 可视模式下的非递归按键绑定
    "vim.operatorPendingModeKeyBindings": [],
    // 下面定义的按键将交由vscode进行处理,而不是vscode-vim插件
    "vim.handleKeys": {
        "<C-a>": false,
        "<C-f>": false
    },

热键配置区域说明

基本上vim的所有模式你都可以配置在下面的4个选项中:

    // 普通模式下的非递归按键绑定
    "vim.normalModeKeyBindingsNonRecursive": [],
    // 插入模式下的非递归按键绑定
    "vim.insertModeKeyBindings": [],
    // 命令模式下的非递归按键绑定
    "vim.commandLineModeKeyBindingsNonRecursive": [],
    // 可视模式下的非递归按键绑定
    "vim.operatorPendingModeKeyBindings": [],

自用热键方案 (keybindings.json)

vim+vscode 全键盘热键方案 - 对于非代码编辑区的热键将其定义在 keybindings.json 中,对于代码编辑区且属于 vim 的热键将其定义在 settings.json 文件中。

全局配置

全局命令定义

ctrl + g c : 显示命令面板
ctrl + g s : 打开设置页面
ctrl + g p : 工作空间文件快速打开
ctrl + g m : 打开一个目录
ctrl + g f : 打开一个文件
ctrl + g h : 打开最近记录
ctrl + g n : 新建vscode实例
ctrl + g q : 关闭vscode示例
    // --- global command ---
    // 显示命令面板
    {
        "key": "ctrl+g c",
        "command": "workbench.action.showCommands"
    },
    // 打开设置页面
    {
        "key": "ctrl+g s",
        "command": "workbench.action.openSettings"
    },
    // 工作空间文件快速打开
    {
        "key": "ctrl+g p",
        "command": "workbench.action.quickOpen"
    },
    // 打开一个目录
    {
        "key": "ctrl+g m",
        "command": "workbench.action.files.openFolder"
    },
    // 打开一个文件
    {
        "key": "ctrl+g f",
        "command": "workbench.action.files.openFile"
    },
    // 打开最近记录
    {
        "key": "ctrl+g h",
        "command": "workbench.action.openRecent"
    },
    // 新建vscode实例
    {
        "key": "ctrl+g n",
        "command": "workbench.action.newWindow"
    },
    // 关闭vscode实例
    {
        "key": "ctrl+g q",
        "command": "workbench.action.closeWindow"
    },

文件命令定义

ctrl + f n : 新建文件
ctrl + f o : 打开文件
ctrl + f e : 另存为文件
ctrl + f s : 保存文件
ctrl + f w : 保存所有文件
ctrl + f q : 关闭文件
ctrl + f a : 关闭所有文件
    // --- file command --- 
    // 新建文件
    {
        "key": "ctrl+f n",
        "command": "welcome.showNewFileEntries",
    },
    // 打开文件
    {
        "key": "ctrl+f o",
        "command": "workbench.action.files.openFileFolder"
    },
    // 另存为文件
    {
        "key": "ctrl+f e",
        "command": "workbench.action.files.saveAs"
    },
    // 保存文件
    {
        "key": "ctrl+f s",
        "command": "workbench.action.files.save"
    },
    // 保存所有文件
    {
        "key": "ctrl+f w",
        "command": "workbench.action.files.saveAll"
    },
    // 关闭文件
    {
        "key": "ctrl+f q",
        "command": "workbench.action.closeActiveEditor"
    },
    // 关闭所有文件
    {
        "key": "ctrl+f a",
        "command": "workbench.action.closeAllEditors"
    },

侧边栏命令定义

ctrl + n [ : 切换侧边栏显示状态
ctrl + n 1 : 显示文件资源管理器
ctrl + n 2 : 显示全局搜索
ctrl + n 3 : 显示版本控制
ctrl + n 4 : 显示debug
ctrl + n 5 : 显示插件商店
ctrl + n 6 : 显示TODO Tree
ctrl + n 7 : 显示Bookmark
​ctrl + n 7 : 显示cnblog account
    // --- side bar command --- 
    // 切换侧边栏显示状态
    {
        "key": "ctrl+n [",
        "command": "workbench.action.toggleSidebarVisibility"
    },
    // 显示文件资源管理器
    {
        "key": "ctrl+n 1",
        "command": "workbench.files.action.focusFilesExplorer"
    },
    // 显示全局搜索
    {
        "key": "ctrl+n 2",
        "command": "workbench.action.replaceInFiles"
    },
    // 显示版本控制
    {
        "key": "ctrl+n 3",
        "command": "workbench.view.scm",
        "when": "workbench.scm.active"
    },
    // 显示debug
    {
        "key": "ctrl+n 4",
        "command": "workbench.view.debug",
        "when": "viewContainer.workbench.view.debug.enabled"
    },
    // 显示插件商店
    {
        "key": "ctrl+n 5",
        "command": "workbench.view.extensions",
        "when": "viewContainer.workbench.view.extensions.enabled"
    },
    // 显示TODO Tree
    {
        "key": "ctrl+n 6",
        "command": "todo-tree-view.focus"
    },
    // 显示Bookmark
    {
        "key": "ctrl+n 7",
        "command": "bookmarksExplorer.focus"
    },
    // cnblogs-account
    {
        "key": "ctrl+n 8",
        "command": "cnblogs-account.focus"
    },

面板命令定义

ctrl + p [ : 切换面板显示状态
ctrl + p 1 : 显示问题
ctrl + p 2 : 显示输出
ctrl + p 3 : 显示终端
ctrl + p 4 : 显示调试控制台
    // --- panel command ---
    // 切换面板显示状态
    {
        "key": "ctrl+p [",
        "command": "workbench.action.togglePanel"
    },
    // 显示问题
    {
        "key": "ctrl+p 1",
        "command": "workbench.panel.markers.view.focus"
    },
    // 显示输出
    {
        "key": "ctrl+p 2",
        "command": "workbench.action.output.toggleOutput",
        "when": "workbench.panel.output.active"
    },
    // 显示终端
    {
        "key": "ctrl+p 3",
        "command": "workbench.action.terminal.toggleTerminal",
        "when": "terminal.active"
    },
    // 显示调试控制台
    {
        "key": "ctrl+p 4",
        "command": "workbench.debug.action.toggleRepl",
        "when": "workbench.panel.repl.view.active"
    },

编辑区命令定义

ctrl + q :关闭当前选项卡或分屏
ctrl + e :聚焦在第一个选项卡中
ctrl + , :切换到上一个选项卡
ctrl + . :切换到下一个选项卡
​
ctrl + w s :拆分一个上下分屏
ctrl + w v :拆分一个左右分屏
​
ctrl + w k :将光标向上移动1屏
ctrl + w j :将光标向下移动1屏
​
ctrl + w h :将光标向左移动1屏
ctrl + w l :将光标向右移动1屏
    // --- editor command ---
    // 关闭当前选项卡或分屏
    {
        "key": "ctrl+q",
        "command": "workbench.action.closeActiveEditor"
    },
    // 聚集在第一个选项卡中
    {
        "key": "ctrl+e",
        "command": "workbench.action.focusFirstEditorGroup"
    },
    // 切换到上一个选项卡
    {
        "key": "ctrl+,",
        "command": "workbench.action.previousEditor"
    },
    // 切换到下一个选项卡
    {
        "key": "ctrl+.",
        "command": "workbench.action.nextEditor"
    },
    // 拆分一个上下分屏
    {
        "key": "ctrl+w s",
        "command": "workbench.action.splitEditorDown"
    },
    // 拆分一个左右分屏
    {
        "key": "ctrl+w v",
        "command": "workbench.action.splitEditor"
    },
    // 将光标向上动0屏
    {
        "key": "ctrl+w k",
        "command": "workbench.action.focusAboveGroup"
    },
    // 将光标向下动0屏
    {
        "key": "ctrl+w j",
        "command": "workbench.action.focusBelowGroup"
    },
    // 将光标向左移动0屏
    {
        "key": "ctrl+w h",
        "command": "workbench.action.focusLeftGroup"
    },
    // 将光标向右移动0屏
    {
        "key": "ctrl+w l",
        "command": "workbench.action.focusRightGroup"
    },

代码编辑区命令定义

ctrl + h : 触发帮助提示
ctrl + j : 触发参数提示
ctrl + k : 触发建议提示
ctrl + n : 移动到下一个建议
ctrl + p : 移动到上一个建议
ctrl + \ : 快速修正
tab      : 选择下一个建议
enter    : 选择当前建议

ctrl + alt + l : 格式化代码(个人习惯)
 ​
ctrl + = : 放大字体
ctrl + - : 缩小字体

ctrl + [ : 快速缩进
ctrl + ] : 快速退格

// 编辑模式
alt + j  : 光标上移
alt + k  : 光标下移
alt + h  : 光标左移
alt + l  : 光标右移
    // --- coding command  --- 
    // 触发帮助提示
    {
        "key": "ctrl+h",
        "command": "editor.action.showHover",
        "when": "editorTextFocus"
    },
    // 触发参数提示
    {
        "key": "ctrl+j",
        "command": "editor.action.triggerParameterHints",
        "when": "editorHasSignatureHelpProvider && editorTextFocus"
    },
    {
        "key": "ctrl+j",
        "command": "closeParameterHints",
        "when": "editorFocus && parameterHintsVisible"
    },
    // 触发建议提示
    {
        "key": "ctrl+k",
        "command": "editor.action.triggerSuggest",
        "when": "editorHasCompletionItemProvider && textInputFocus && !editorReadonly"
    },
    {
        "key": "ctrl+k",
        "command": "hideSuggestWidget",
        "when": "suggestWidgetVisible && textInputFocus"
    },
    // 移动到下一个建议
    {
        "key": "ctrl+n",
        "command": "selectNextSuggestion",
        "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
    },
    // 移动到上一个建议
    {
        "key": "ctrl+p",
        "command": "selectPrevSuggestion",
        "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus"
    },
    // 快速修正
    {
        "key": "ctrl+\\",
        "command": "editor.action.quickFix",
        "when": "editorHasCodeActionsProvider && editorTextFocus && !editorReadonly",
    },
    // 格式化代码
    {
        "key": "ctrl+alt+l",
        "command": "editor.action.formatDocument",
        "when": "editorHasDocumentFormattingProvider && editorTextFocus && !editorReadonly && !inCompositeEditor"
    },
    // 放大字体
    {
        "key": "ctrl+=",
        "command": "editor.action.fontZoomIn"
    },
    // 缩小字体
    {
        "key": "ctrl+-",
        "command": "editor.action.fontZoomOut"
    },
    // 快速缩进
    {
        "key": "ctrl+[",
        "command": "tab"
    },
    // 快速退格
    {
        "key": "ctrl+]",
        "command": "outdent"
    },
    // 编辑模式 - 光标下、上、左、右移
    {
        "key": "alt+j",
        "command": "cursorDown",
        "when": "editorTextFocus"
    },
    {
        "key": "alt+k",
        "command": "cursorUp",
        "when": "editorTextFocus"
    },
    {
        "key": "alt+h",
        "command": "cursorLeft",
        "when": "editorTextFocus"
    },
    {
        "key": "alt+l",
        "command": "cursorRight",
        "when": "editorTextFocus"
    },

取消 vim 与 vscode 一些指令

ctrl+a    : 全选, 非 INSERT 模式不生效
ctrl+c(v) : 复制(粘贴), 非 INSERT 模式不生效
    // --- 取消一些vim插件的额外功能
    {
        "key": "ctrl+a",
        "command": "-extension.vim_cmd+a",
        "when": "editorTextFocus && vim.active && vim.use<D-a> && !inDebugRepl && vim.mode != 'Insert'"
    },
    {
        "key": "alt+ctrl+down",
        "command": "-extension.vim_cmd+alt+down",
        "when": "editorTextFocus && vim.active && !inDebugRepl"
    },
    {
        "key": "alt+ctrl+up",
        "command": "-extension.vim_cmd+alt+up",
        "when": "editorTextFocus && vim.active && !inDebugRepl"
    },
    {
        "key": "ctrl+c",
        "command": "-extension.vim_cmd+c",
        "when": "editorTextFocus && vim.active && vim.overrideCopy && vim.use<D-c> && !inDebugRepl"
    },
    {
        "key": "ctrl+v",
        "command": "-extension.vim_cmd+v",
        "when": "editorTextFocus && vim.active && vim.use<D-v> && vim.mode == ''CommandlineInProgress' !inDebugRepl' || editorTextFocus && vim.active && vim.use<D-v> && !inDebugRepl && vim.mode == 'SearchInProgressMode'"
    },
    {
        "key": "ctrl+d",
        "command": "-extension.vim_cmd+d",
        "when": "editorTextFocus && vim.active && vim.use<D-d> && !inDebugRepl"
    },
    {
        "key": "ctrl+left",
        "command": "-extension.vim_cmd+left",
        "when": "editorTextFocus && vim.active && vim.use<D-left> && !inDebugRepl && vim.mode != 'Insert'"
    },
    {
        "key": "ctrl+right",
        "command": "-extension.vim_cmd+right",
        "when": "editorTextFocus && vim.active && vim.use<D-right> && !inDebugRepl && vim.mode != 'Insert'"
    },
    // --- 取消或更改一些vscode键位
    // ctrl+a全选功能在非INSERT模式下不生效
    {
        "key": "ctrl+a",
        "command": "editor.action.selectAll",
        "when": "vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualLine' && vim.mode != 'VisualBlock' && vim.mode != 'CommandlineInProgress'"
    },
    {
        "key": "ctrl+a",
        "command": "-editor.action.selectAll"
    },
    // ctrl+c或者cmd+v功能在非INSERT模式下不生效
    {
        "key": "ctrl+c",
        "command": "-editor.action.clipboardCopyAction"
    },
    {
        "key": "ctrl+v",
        "command": "-editor.action.clipboardPasteAction"
    },
    {
        "key": "ctrl+c",
        "command": "-execCopy"
    },
    {
        "key": "ctrl+c",
        "command": "execCopy",
        "when": "vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualLine' && vim.mode != 'VisualBlock' && vim.mode != 'CommandlineInProgress'"
    },
    {
        "key": "ctrl+v",
        "command": "-execPaste",
    },
    {
        "key": "ctrl+v",
        "command": "execPaste",
        "when": "vim.mode != 'Normal' && vim.mode != 'Visual' && vim.mode != 'VisualLine' && vim.mode != 'VisualBlock' && vim.mode != 'CommandlineInProgress'"
    },

资源管理配置

j     : 向下移动
k     : 向上移动
space : 打开文件或目录
​
新增:​
alt+x : 折叠文件夹
i     : 新增文件
o     : 新增目录
r     : 刷新目录
a     : 重命名文件或目录
d     : 删除文件或目录
x     : 剪切文件或目录
y     : 复制文件或目录
p     : 粘贴文件或目录
    // --- 资源管理器中对文件或目录的操作
    // 折叠资源管理器文件夹
    {
        "key": "alt+x",
        "command": "workbench.files.action.collapseExplorerFolders",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 新建文件
    {
        "key": "i",
        "command": "explorer.newFile",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 新建目录
    {
        "key": "o",
        "command": "explorer.newFolder",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 刷新资源管理器
    {
        "key": "r",
        "command": "workbench.files.action.refreshFilesExplorer",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 重命名文件或目录
    {
        "key": "a",
        "command": "renameFile",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 删除文件或目录
    {
        "key": "d",
        "command": "deleteFile",
        "when": " explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus "
    },
    // 剪切文件或目录
    {
        "key": "x",
        "command": "filesExplorer.cut",
        "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !explorerResourceReadonly && !inputFocus"
    },
    // 复制文件或目录
    {
        "key": "y",
        "command": "filesExplorer.copy",
        "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceIsRoot && !inputFocus"
    },
    // 粘贴文件或目录
    {
        "key": "p",
        "command": "filesExplorer.paste",
        "when": "explorerViewletVisible && filesExplorerFocus && !explorerResourceReadonly && !inputFocus"
    },

插件描述

输入法切换

设置 NORMAL 模式下的输入法为英文, 方便进行 vim 指令操作。

  • Windows scoop 安装
scoop bucket add im-select https://github.com/daipeihust/im-select
scoop install im-select

切换至英文输入法获取输入法别名。

im-select.exe
1033

然后再到 settings.json 中加入以下配置项即可完成输入法在 INSERT 模式以及 NORMAL 模式下的自动切换。

    // 自动切换输入法
    "vim.autoSwitchInputMethod.enable": true,
    "vim.autoSwitchInputMethod.defaultIM": "1033",  // 这里输入你刚刚获得的英文输入法名称
    "vim.autoSwitchInputMethod.obtainIMCmd": "C:/Users/User/scoop/apps/im-select/current/im-select.exe",
    "vim.autoSwitchInputMethod.switchIMCmd": "C:/Users/User/scoop/apps/im-select/current/im-select.exe {im}"

内置插件

  • vim-esaymotion, 它的作用是通过以下的按键组合,你可以快速的定位到任何你想修改的行中:
<leader><leader>s<char>
  • vim-surround, 修改、或者删除符号:
ds<existing>
cs<existing><desired>
  • vim-commentary, 该插件能够快速的利用键盘进行行或者块的注释:
gcc :行注释
gCC :块注释

快捷指令

gd : 跳转到函数定义或引用处,搭配 ctrl+i/ctrl+o 查看源码很方便
gh : 触发帮助提示
gb : 开启多光标模式,选中和当前单词相同的单词

标签:key,ctrl,vscode,vim,键盘,command,&&,action
From: https://www.cnblogs.com/m-contour/p/17214921.html

相关文章