VS Code VIM 扩展复制粘贴 [英] VS code VIM extension copy and paste

查看:116
本文介绍了VS Code VIM 扩展复制粘贴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有使用 vim 扩展名复制和粘贴 vs 代码的正常方法?

Is there a normal way to copy and paste in vs code using vim extension?

我已经尝试将 VIM 寄存器命令映射到我习惯的快捷命令(ctrl + c 用于复制,ctrl + v 用于粘贴),但结果很奇怪,我不知道该怎么做正确.

I've tried mapping VIM register commands to the shortcut commands I'm used to (ctrl + c for copying and ctrl + v for pasting), but the results are pretty weird and I'm not sure how to do this correctly.

虽然使用 vim 键绑定非常简单,vimrc 文件:

While using vim the key bindings were quite simple, vimrc file:

map <C-c> "+y
map <C-v> "+p

现在我尝试通过编辑 json.settings 文件将它们迁移到 vs-code:

Now I try to migrate those to vs-code by editting json.settings file:

{
    "vim.visualModeKeyBindings": [
        {
            "before": ["<C-c>"],
            "after": ["\"", "+", "y"]
        },
        {
            "before": ["<C-v>"], 
            "after":  ["\"", "+", "p"]
        },
    ], }

我希望它可以在可视模式和正常模式(用于粘贴)下运行,并且能够使用这些快捷方式从剪贴板复制和粘贴.

I want this to operate both in visual mode and in normal mode (for pasting), and be able to copy and paste from clipboard using these shortcuts.

如何正确地做到这一点?有没有另一种方法可以做到这一点?

How to do this correctly? Is there another way to do this?

推荐答案

您可以简单地停止 vscodevim 扩展处理 Ctrl-CCtrl-V 完全,然后允许 VSCode 本地处理它们.这可以通过将以下代码放在扩展的 settings.json 文件中来完成:

Rather than rebinding, you can simply stop the vscodevim extension from handling Ctrl-C and Ctrl-V entirely, which then allows VSCode to handle them natively. This can be done by placing the below code in the extension's settings.json file:

"vim.handleKeys": {
    "<C-c>": false,
    "<C-v>": false
}

无论您处于哪种模式,这都可以工作,并且可以完美地适应系统剪贴板.我不确定 是否必要,但 肯定是必要的,如 ; 是进入可视块模式的标准 Vim 和弦.

This will work regardless of which mode you're in, and will perfectly accommodate the system clipboard. I'm not sure if the <C-c> is necessary, but the <C-v> definitely is, as <C-v> is the standard Vim chord to enter visual block mode.

顺便说一句,您的重新绑定方法是完全有效的;它只需要更多的代码:

As an aside, your rebind method is perfectly valid; it just requires a bit more code:

// For visual mode
"vim.visualModeKeyBindings": [
  {
    "before": ["<C-c>"],
    "after": ["\"", "+", "y"]
  },
  {
    "before": ["<C-v>"], 
    "after":  ["\"", "+", "p"]
  }
],
// For normal mode
"vim.normalModeKeyBindings": [
  {
    "before": ["<C-c>"],
    "after": ["\"", "+", "y"]
  },
  {
    "before": ["<C-v>"], 
    "after":  ["\"", "+", "p"]
  }
]

这篇关于VS Code VIM 扩展复制粘贴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆