Skip to main content

VSCode Vim

VSCode Vim 扩展特有技巧.

代码收起展开

  • zc 收起代码块
  • zo 展开代码块
  • zR 收起所有代码块
  • zM 展开所有代码块

文本对象

引用资料:

内置文本对象列表:

  • aw: Select "a word"
  • iw: Select "inner word"
  • aW: Select "a WORD"
  • iW: Select "inner WORD"
  • as: Select "a sentence"
  • is: Select "inner sentence"
  • ap: Select "a paragraph"
  • ip: Select "inner paragraph"
  • a], a[: select [ ] blocks
  • i], i[: select inner [ ] blocks
  • ab, a(, a): Select "a block" ( from [( to ]) )
  • ib, i), i(: Select "inner block" ( from [( to ]) )
  • aB, a{, a}: Select "a Block" (from [{ to ]})
  • iB, i{, i}: Select "inner Block" (from [{ to ]})
  • at: Select "a tag block" (from <aaa> to </aaa>)
  • it: Select "inner tag block" (from <aaa> to </aaa>)
  • a': Select "a single quoted string"
  • i': Select "inner single quoted string"
  • a": Select "a double quoted string"
  • i": Select "inner double quoted string"
  • ia: Select "inner argument" from the targets.vim plugin
  • aa: Select "an argument" from the targets.vim plugin
* a>, a< : Select "a *<>* block" 
* i>, i< : Select "inner *<>* block"
* a` : Select "a backward quoted string"
* i` : Select "inner backward quoted string"

自定义快捷键

Vim 可以分别设置 Normal(vim.normalModeKeyBindings)模式和Insert(vim.insertModeKeyBindings)模式下的快捷键.

Vim 为了防止用户自定义快捷键和 Vim 内置快捷键冲突, 会在用户自定义快捷键前面加上一个 「Leader Key」记作 <Leader>, 默认为 \, 你可以在 VSCode 的设置中找到 vim.leader 来修改它, 比如:

settings.json
{
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["<Leader>", "p"],
"commands": [
"workbench.action.showCommands",
]
},
]
}

然后在 Vim Normal模式下, 按 \p 即可唤起VSCode命令行面板.

引用

我的最终配置

settings.json
{
// "vim.autoSwitchInputMethod.enable": true,
// "vim.autoSwitchInputMethod.defaultIM": "xkb:us::eng",
// "vim.autoSwitchInputMethod.obtainIMCmd": "/usr/bin/ibus engine",
// "vim.autoSwitchInputMethod.switchIMCmd": "/usr/bin/ibus engine {im}"
// "vim.leader": "\\",
"vim.leader": " ",
"vim.useCtrlKeys": false,
"vim.useSystemClipboard": true,
"vim.smartRelativeLine": true,
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": [
"<Leader>",
"p"
],
"commands": [
"workbench.action.showCommands"
]
},
{
"before": [
"K"
],
"commands": [
"editor.action.showHover"
]
},
],
"vim.visualModeKeyBindings": [
{
"before": [
"J"
],
"commands": [
"editor.action.moveLinesDownAction"
]
},
{
"before": [
"K"
],
"commands": [
"editor.action.moveLinesUpAction"
]
}
]
}