1

I'm remapping keys in settings.json (VS Code) like that:

  "vim.normalModeKeyBindingsNonRecursive": [
    {
      "before":["<S-j>"],
      "commands": [
        ":m-2",
      ]
    },
    {
      "before":["<S-k>"],
      "commands": [
        ":m+",
      ]
    } 
  ]  

So when I try to type Shift-k, I see :m+ in Vim command line but it's not performed. I think I need to use <CR> somehow, but I don't know how.

Wahlstrommm
  • 684
  • 2
  • 7
  • 21
  • In **VSCode**, there is no need to add ``, for example in the *Quick Example* of the extension doc, just use the `"commands": [":nohl"]` there. – Rocco May 17 '23 at 13:50
  • @Rocco Yes I know, but as I mentioned, it doesn’t work, I see :nohl in Vim command line but it's not performed. – Kirill Stepankov May 23 '23 at 15:15
  • This comment is just an addition, the specific reason I wrote in the answer: the *Ex command* `move` of Vim is not implemented in VSCode currently, If you want to achieve the same function of your code, you can do as suggested in the answer. – Rocco May 23 '23 at 15:40

1 Answers1

2

Currently, most of the Ex commands of Vim is not implemented in VSCode, you need to map the keys to the internal implementation and commands of VSCode. For example, if you want to move line up/down, you can add mappings for Normal mode and Visual mode like this:

{
    "vim.visualModeKeyBindings": [
        {
            "before": [ "K" ],
            "commands": [ "editor.action.moveLinesUpAction" ]
        },
        {
            "before": [ "J" ],
            "commands": [ "editor.action.moveLinesDownAction" ]
        }
    ],
    "vim.normalModeKeyBindings": [
        {
            "before": [ "K" ],
            "commands": [ "editor.action.moveLinesUpAction" ]
        },
        {
            "before": [ "J" ],
            "commands": [ "editor.action.moveLinesDownAction" ]
        }
    ]
}

IMHO, J itself is a useful command, so I mapped these two commands to _ and -.

Similarly, if you want to copy line up/down, you can map the editor.action.copyLinesUpAction / editor.action.copyLinesDownAction command. To get other commands, you can open the Keyboard Shortcuts list, then right click and copy command ID. For more to see VSCode Key Bindings and Built-in Commands.

Rocco
  • 471
  • 1
  • 3
  • 7