vs code 安装 vim 插件 后输入效率大大提高,可是vim的d y p这几个命令使用起来可没那么爽。老是打破ctrl+c ctrl+v ctrl+x的习惯。每次删除都会修改剪贴板。
那么能不能让vim直接调用vs code 的copy , paste , delete line命令呢,答案是可以的。
设置如下
File=>Preferences=>Settings
"vim.normalModeKeyBindingsNonRecursive": [
{
"before": ["d","d"],
"commands":["editor.action.deleteLines"],
"when":"textInputFocus && !editorReadonly"
},
{
"before":["y"],
"commands":["editor.action.clipboardCopyAction"],
"when":"textInputFocus"
},
{
"before":["y","y"],
"commands":["editor.action.clipboardCopyAction"],
"when":"textInputFocus"
},
{
"before":["p"],
"commands":["editor.action.clipboardPasteAction"],
"when":"textInputFocus && !editorReadonly"
}
],
"vim.visualModeKeyBindingsNonRecursive":[
{
"before":["y"],
"commands":["editor.action.clipboardCopyAction"],
"when":"textInputFocus"
},
{
"before":["y","y"],
"commands":["editor.action.clipboardCopyAction"],
"when":"textInputFocus"
},
{
"before":["x"],
"commands":["deleteRight"],
"when":"textInputFocus"
},
]
使用起来爽爽的
参考文章
https://stackoverflow.com/questions/11993851/how-to-delete-not-cut-in-vim
https://github.com/VSCodeVim/Vim/#key-remapping
File=>Preferences=>Keyboard Shortcuts

本文介绍如何在VSCode中通过自定义Vim插件的映射,实现与VSCode剪切板操作(复制、粘贴、删除行)的无缝衔接,提升编辑效率。通过设置文件>首选项>设置,可以将Vim的d,d,y,p等命令映射为VSCode的内置命令,避免了剪贴板被意外覆盖的问题。
1万+





