如何在 Visual Studio Code 中使用 vim 模式切换多行注释

Phi*_*ord 3 visual-studio-code

我在 Mac 上使用 VS Code,使用 Vim 模拟。

如果我有一个.py这样的文件:

test1 = 1

test2 = 2
Run Code Online (Sandbox Code Playgroud)

我选择所有三行,然后按<cmd>/我得到:

# test1 = 1

# test2 = 2
Run Code Online (Sandbox Code Playgroud)

我想要使​​用 vim 命令序列<leader>, then c, then 来实现相同的功能<space>

在我的settings.json我有这个:

{
  "vim.leader": ",",
  "vim.normalModeKeyBindings": [
    {
      "before": ["<leader>", "c", "<space>"],
      "commands": ["editor.action.commentLine"],
      "when": "editorTextFocus && !editorReadonly"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

但是,使用该序列,虽然我可以选择一行来打开/关闭注释,但当我选择多行时,它不会执行任何操作。为什么?

小智 5

请尝试将以下内容添加到您的 settings.json 中,并告诉我它是否适合您。这对我有用。

"vim.visualModeKeyBindings": [
  {
    "before": ["<leader>", "c"],
    "commands": ["editor.action.commentLine"],
    "when": "editorTextFocus && !editorReadonly"
  }
],
Run Code Online (Sandbox Code Playgroud)