个人VSCode Vim基础配置文件
基础配置项
vscode-vim插件由于是一款模拟器,所以它的配置文件是放在settings.json文件中,而不是vimrc文件中,个人也并不推荐将配置放在vimrc文件中,因为这会导致多端同步变的复杂,尽管这款插件可以支持从vimrc文件中读取配置。
setting.json
// 启用vimrc文件
"vim.vimrc.enable": true,
// vimrc文件
"vim.vimrc.path": "$HOME/.vimrc",
// 启用相对行号
"editor.lineNumbers": "relative",
// 绑定vim前导键
"vim.leader": "<space>",
// 启用easymotion插件
"vim.easymotion": true,
// 启用系统粘贴板作为vim寄存器
"vim.useSystemClipboard": false,
// 由vim接管ctrl+any的按键,而不是vscode
"vim.useCtrlKeys": true,
// 突出显示与当前搜索匹配的所有文本
"vim.hlsearch": true,
// 普通模式下的非递归按键绑定
"vim.normalModeKeyBindingsNonRecursive": [],
// 插入模式下的非递归按键绑定
"vim.insertModeKeyBindings": [
{
"before": ["alt+j"],
"after": ["j"]
}
],
// 命令模式下的非递归按键绑定
"vim.commandLineModeKeyBindingsNonRecursive": [],
// 可视模式下的非递归按键绑定
"vim.operatorPendingModeKeyBindings": [],
// 下面定义的按键将交由vscode进行处理,而不是vscode-vim插件
"vim.handleKeys": {
"<C-a>": false,
"<C-z>": false,
"<C-x>": false,
"<C-c>": false,
"<C-v>": false,
"<C-f>": false,
"<C-w>": false,
"<C-n>": false,
"<C-y>": false,
}
(1)热键配置项
基本上vim的所有模式你都可以配置在下面的4个选项中:
// 普通模式下的非递归按键绑定
"vim.normalModeKeyBindingsNonRecursive": [],
// 插入模式下的非递归按键绑定
"vim.insertModeKeyBindings": [],
// 命令模式下的非递归按键绑定
"vim.commandLineModeKeyBindingsNonRecursive": [],
// 可视模式下的非递归按键绑定
"vim.operatorPendingModeKeyBindings": [],
// 下面定义的按键将交由vscode进行处理,而不是vscode-vim插件
"vim.handleKeys": {
"<C-a>": false,
"<C-f>": false
}
(2)还可以使用$HOME/.vimrc
文件配置,键盘映射,等与其他ide-vim插件通用配置放在此处
" Key Remapping
imap jk <Esc>
(3)也可以在vscode中配置,在INSERT模式下使用jj退回到NORMAL模式:
"vim.insertModeKeyBindings": [
{
"before": [
"j",
"j"
],
"after": [
"<Esc>"
]
},
],
keybindings.json
(旧版)
在终端和编辑器中来回切换比较频繁,为这个按键绑定了 alt + t
// Place your key bindings in this file to overwrite the defaults
[
{ // 查找
"key": "cmd+f",
"command": "actions.find",
"when": "editorFocus || editorIsOpen"
},
{ // 替换
"key": "ctrl+h",
"command": "editor.action.startFindReplaceAction",
"when": "editorFocus || editorIsOpen"
},
{
"key": "alt+m",
"command": "bookmarks.toggle",
"when": "editorTextFocus"
},
{ // 热键冲突
"key": "shift+alt+up",
"command": "editor.action.insertCursorAbove",
"when": "editorTextFocus"
},
{
"key": "shift+alt+down",
"command": "editor.action.insertCursorBelow",
"when": "editorTextFocus"
},
{ // 关闭窗口
"key": "alt+e",
"command": "workbench.action.closeActiveEditor"
},
{ // 全屏
"key": "f11",
"command": "workbench.action.exitZenMode",
"when": "inZenMode"
},
{ // 格式化
"key": "shift+alt+f",
"command": "editor.action.formatDocument",
"when": "editorTextFocus && !editorReadonly"
},
{ // 切换语言
"key": "alt+l",
"command": "workbench.action.editor.changeLanguageMode"
},
{ // 取消python插件选中行运行
"key": "shift+enter",
"command": "-python.execSelectionInTerminal",
"when": "editorFocus && !findInputFocussed && !python.datascience.hascodecells && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "shift+enter",
"command": "-python.datascience.runcurrentcelladvance",
"when": "editorFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection"
},
{
"key": "shift+enter",
"command": "-python.datascience.execSelectionInteractive",
"when": "editorFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "shift+enter",
"command": "-python.execSelectionInTerminal",
"when": "editorFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
},
{ // 大小写设置
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorHasSelection"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorHasSelection"
},
{ // 匹配项选择
"key": "ctrl+a",
"command": "editor.action.selectHighlights",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "cmd+a",
"command": "editor.action.selectHighlights",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "ctrl+e",
"command": "editor.action.moveSelectionToPreviousFindMatch",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "cmd+e",
"command": "editor.action.moveSelectionToPreviousFindMatch",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "ctrl+shift+l",
"command": "-editor.action.selectHighlights",
"when": "editorFocus"
},
{ // 删除一行
"key": "shift+delete",
"command": "editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "shift+cmd+k",
"command": "-editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
},
{ // 注释
"key": "ctrl+/",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "cmd+/",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{ // 高亮选中
"key": "ctrl+shift+h",
"command": "highlightwords.addHighlight",
"when": "editorFocus && editorHasSelection"
},
{
"key": "ctrl+shift+h",
"command": "highlightwords.addRegExpHighlight",
"when": "editorFocus && !editorHasSelection"
},
{
"key": "ctrl+shift+h",
"command": "highlightwords.toggleSidebar",
},
// 跳转
{ // 打开文件
"key": "alt+o",
"command": "workbench.action.quickOpen",
},
{ // 打开工作区符号
"key": "alt+s",
"command": "workbench.action.showAllSymbols",
"when": "editorFocus"
},
{ // 打开文件符号
"key": "alt+f",
"command": "workbench.action.gotoSymbol",
"when": "editorFocus"
},
{ // 跳转到行
"key": "alt+g",
"command": "workbench.action.gotoLine",
"when": "editorFocus"
},
{ // 切换上一个编辑器
"key": "alt+h",
"command": "workbench.action.previousEditor"
},
{ // 切换下一个编辑器
"key": "alt+l",
"command": "workbench.action.nextEditor"
},
{ // 跳转到定义
"key": "alt+d",
"command": "editor.action.revealDefinition",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
},
{ // 跳转到类型定义
"key": "alt+shift+d",
"command": "editor.action.goToTypeDefinition",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor"
},
{ // 跳转到实现
"key": "alt+i",
"command": "editor.action.goToImplementation",
"when": "editorHasImplementationProvider && editorTextFocus && !isInEmbeddedEditor"
},
{ // 跳转到引用
"key": "alt+r",
"command": "editor.action.goToReferences",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor"
},
{ // 跳转到引用面板
"key": "shift+alt+r",
"command": "references-view.findReferences",
"when": "editorHasReferenceProvider"
},
{ // 返回
"key": "alt+j",
"command": "workbench.action.navigateBack"
},
{ // 前进
"key": "alt+k",
"command": "workbench.action.navigateForward"
},
{ // 终端/工作区互跳
"key": "alt+t",
"command": "workbench.action.terminal.focus",
"when": "editorFocus"
},
{ // 终端/工作区互跳
"key": "alt+t",
"command": "workbench.action.focusFirstEditorGroup",
"when": "terminalFocus",
},
{ // 折叠切换
"key": "alt+c",
"command": "editor.toggleFold",
"when": "editorTextFocus && foldingEnabled"
},
{ // 全部折叠
"key": "alt+a",
"command": "editor.foldAll",
"when": "editorTextFocus && foldingEnabled"
},
{ // 全部展开
"key": "alt+u",
"command": "editor.unfoldAll",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 1 级
"key": "alt+1",
"command": "editor.foldLevel1",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 2 级
"key": "alt+2",
"command": "editor.foldLevel2",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 3 级
"key": "alt+3",
"command": "editor.foldLevel3",
"when": "editorTextFocus && foldingEnabled"
},
{
"key": "alt+w",
"command": "workbench.action.showAllEditors"
},
]
keybindings.json
(新版)
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "shift+alt+n",
"command": "projectManager.listProjectsNewWindow"
},
{ // 查找
"key": "cmd+f",
"command": "actions.find",
"when": "editorFocus || editorIsOpen"
},
{ // 替换
"key": "ctrl+h",
"command": "editor.action.startFindReplaceAction",
"when": "editorFocus || editorIsOpen"
},
{
"key": "alt+m",
"command": "bookmarks.toggle",
"when": "editorTextFocus"
},
{ // 热键冲突
"key": "shift+alt+up",
"command": "editor.action.copyLinesUpAction",
"when": "editorTextFocus"
},
{
"key": "shift+alt+down",
"command": "editor.action.copyLinesDownAction",
"when": "editorTextFocus"
},
{ // 关闭窗口
"key": "alt+e",
"command": "workbench.action.closeActiveEditor"
},
{ // 全屏
"key": "f11",
"command": "workbench.action.exitZenMode",
"when": "inZenMode"
},
{ // 格式化
"key": "shift+alt+f",
"command": "editor.action.formatDocument",
"when": "editorTextFocus && !editorReadonly"
},
{ // 切换语言
"key": "alt+l",
"command": "workbench.action.editor.changeLanguageMode"
},
{ // 取消python插件选中行运行
"key": "shift+enter",
"command": "-python.execSelectionInTerminal",
"when": "editorFocus && !findInputFocussed && !python.datascience.hascodecells && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "shift+enter",
"command": "-python.datascience.runcurrentcelladvance",
"when": "editorFocus && python.datascience.featureenabled && python.datascience.hascodecells && !editorHasSelection"
},
{
"key": "shift+enter",
"command": "-python.datascience.execSelectionInteractive",
"when": "editorFocus && python.datascience.featureenabled && python.datascience.ownsSelection && !findInputFocussed && !replaceInputFocussed && editorLangId == 'python'"
},
{
"key": "shift+enter",
"command": "-python.execSelectionInTerminal",
"when": "editorFocus && !findInputFocussed && !python.datascience.ownsSelection && !replaceInputFocussed && editorLangId == 'python'"
},
{ // 大小写设置
"key": "ctrl+shift+u",
"command": "editor.action.transformToUppercase",
"when": "editorHasSelection"
},
{
"key": "ctrl+shift+l",
"command": "editor.action.transformToLowercase",
"when": "editorHasSelection"
},
{ // 匹配项选择
"key": "ctrl+a",
"command": "editor.action.selectHighlights",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "cmd+a",
"command": "editor.action.selectHighlights",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "ctrl+e",
"command": "editor.action.moveSelectionToPreviousFindMatch",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "cmd+e",
"command": "editor.action.moveSelectionToPreviousFindMatch",
"when": "editorFocus && editorHasSelection && editorHasMultipleSelections"
},
{
"key": "ctrl+shift+l",
"command": "-editor.action.selectHighlights",
"when": "editorFocus"
},
{ // 删除一行
"key": "shift+delete",
"command": "editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
},
{
"key": "shift+cmd+k",
"command": "-editor.action.deleteLines",
"when": "textInputFocus && !editorReadonly"
},
{ // 注释
"key": "ctrl+/",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "cmd+/",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{ // 高亮选中
"key": "ctrl+shift+h",
"command": "highlightwords.addHighlight",
"when": "editorFocus && editorHasSelection"
},
{
"key": "ctrl+shift+h",
"command": "highlightwords.addRegExpHighlight",
"when": "editorFocus && !editorHasSelection"
},
{
"key": "ctrl+shift+h",
"command": "highlightwords.toggleSidebar",
},
// 跳转
{ // 打开文件
"key": "alt+o",
"command": "workbench.action.quickOpen",
},
{ // 打开工作区符号
"key": "alt+s",
"command": "workbench.action.showAllSymbols",
"when": "editorFocus"
},
{ // 打开文件符号
"key": "alt+f",
"command": "workbench.action.gotoSymbol",
"when": "editorFocus"
},
{ // 跳转到行
"key": "alt+g",
"command": "workbench.action.gotoLine",
"when": "editorFocus"
},
{ // 切换上一个编辑器
"key": "alt+h",
"command": "workbench.action.previousEditor"
},
{ // 切换下一个编辑器
"key": "alt+l",
"command": "workbench.action.nextEditor"
},
{ // 跳转到定义
"key": "alt+d",
"command": "editor.action.revealDefinition",
"when": "editorHasDefinitionProvider && editorTextFocus && !isInEmbeddedEditor"
},
{ // 跳转到类型定义
"key": "alt+shift+d",
"command": "editor.action.goToTypeDefinition",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor"
},
{ // 跳转到实现
"key": "alt+i",
"command": "editor.action.goToImplementation",
"when": "editorHasImplementationProvider && editorTextFocus && !isInEmbeddedEditor"
},
{ // 跳转到引用
"key": "alt+r",
"command": "editor.action.goToReferences",
"when": "editorHasReferenceProvider && editorTextFocus && !inReferenceSearchEditor && !isInEmbeddedEditor"
},
{ // 跳转到引用面板
"key": "shift+alt+r",
"command": "references-view.findReferences",
"when": "editorHasReferenceProvider"
},
{ // 返回
"key": "alt+j",
"command": "workbench.action.navigateBack"
},
{ // 前进
"key": "alt+k",
"command": "workbench.action.navigateForward"
},
{ // 终端/工作区互跳
"key": "alt+t",
"command": "workbench.action.terminal.focus",
"when": "editorFocus"
},
{ // 终端/工作区互跳
"key": "alt+t",
"command": "workbench.action.focusFirstEditorGroup",
"when": "terminalFocus",
},
{ // 折叠切换
"key": "alt+c",
"command": "editor.toggleFold",
"when": "editorTextFocus && foldingEnabled"
},
{ // 全部折叠
"key": "alt+a",
"command": "editor.foldAll",
"when": "editorTextFocus && foldingEnabled"
},
{ // 全部展开
"key": "alt+u",
"command": "editor.unfoldAll",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 1 级
"key": "alt+1",
"command": "editor.foldLevel1",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 2 级
"key": "alt+2",
"command": "editor.foldLevel2",
"when": "editorTextFocus && foldingEnabled"
},
{ // 折叠到 3 级
"key": "alt+3",
"command": "editor.foldLevel3",
"when": "editorTextFocus && foldingEnabled"
},
{
"key": "alt+w",
"command": "workbench.action.showAllEditors"
},
]
origin address: https://www.ohyee.cc/post/note_vim
作者:chacebai
出处:https://www.cnblogs.com/chacebai/p/17600826.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!