私的VSCodeでのVim設定

長い間VimでオレオレKeybindingを使い続けているせいで
デフォルトのVSCode+Vim設定が使いにくい...ので備忘として投稿しました。

多分Vimmerからしても微妙な使い方になるのでオススメはしないので、
複数行移動のサンプル程度で

# Vimプラグインの導入

何はともあれVSCodeにVimプラグインを入れることから
https://marketplace.visualstudio.com/items?itemName=vscodevim.vim

# VSCodeのKeyBinding改造

VSCodeのキーバインディング設定
Ctrl+Shift+Pでコマンドパレットを表示し以下のいずれかで編集
操作性が変わるだけで結果は変わらない

- Open Keyboard ShortCuts: リストから編集
- Open Keyboard ShortCuts(JSON): keybindings.jsonを直接編集


## Ctrl系をもとに戻す or 上書き

### Ctrl+Fは普通の検索に使いたい

[Ctrl+F]をvimを上書きされてしまっているのでこれを普通の検索に戻す。


```keybindings.json
    {
        "key": "ctrl+f",
        "command": "-extension.vim_ctrl+f",
        "when": "editorTextFocus && vim.active && vim.use<C-f> && !inDebugRepl && vim.mode != 'Insert'"
    }
```

or Keyboard Shortcuts から`extension.vim_ctrl+f`の項目を削除する

### Ctrl+JをEscに使いたい

```keybindings.json
    {
        "key": "ctrl+j",
        "command": "extension.vim_escape",
        "when": "editorTextFocus && vim.active && !inDebugRepl"
    },
    {
        "key": "ctrl+j",
        "command": "-extension.vim_ctrl+j",
        "when": "editorTextFocus && vim.active && vim.use<C-j> && !inDebugRepl"
    }
```

### Ctrl+Cをコピーに使いたい

```keybindings.json
    {
        "key": "ctrl+c",
        "command": "-extension.vim_ctrl+c",
        "when": "editorTextFocus && vim.active && vim.overrideCtrlC && vim.use<C-c> && !inDebugRepl"
    }
```

## Shift + hjklでサクサク移動したい

### Shift+[hl]で前後のワードに移動したい

※下記だとvisualモード自反映されない問題が有るので良案あれば...

```keybindings.json
    {
        "key": "shift+h",
        "command": "cursorWordAccessibilityLeft",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+l",
        "command": "cursorWordAccessibilityRight",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    }
```

### Shift+[jk]で複数行移動したい

複数コマンド実行は Plugin: [multi-command](https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command) を導入していないとできない気がするので導入

コマンドパレットからOpen Settings(JSON)とかで`settings.json`を開き複数コマンド実行するコマンドを定義する

```settings.json
    "multiCommand.commands": [
        {
            "command": "multiCommand.down4TextLines",
            "sequence": [
                "extension.vim_down",
                "extension.vim_down",
                "extension.vim_down",
                "extension.vim_down",
            ]
        },
        {
            "command": "multiCommand.down4ListLines",
            "sequence": [
                "list.focusDown",
                "list.focusDown",
                "list.focusDown",
                "list.focusDown"
            ]
        },
        {
            "command": "multiCommand.up4TextLines",
            "sequence": [
                "extension.vim_up",
                "extension.vim_up",
                "extension.vim_up",
                "extension.vim_up",
            ]
        },
        {
            "command": "multiCommand.up4ListLines",
            "sequence": [
                "list.focusUp",
                "list.focusUp",
                "list.focusUp",
                "list.focusUp"
            ]
        },
    ],
```

keybindings.jsonからは複数コマンド定義を呼び出す形で記載する

```keybindings.json
    {
        "key": "shift+j",
        "command": "multiCommand.down4TextLines",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+j",
        "command": "multiCommand.down4ListLines",
        "when": "listFocus"
    },
    {
        "key": "shift+k",
        "command": "multiCommand.up4TextLines",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+k",
        "command": "multiCommand.up4ListLines",
        "when": "listFocus"
    },
```

# その他

[ココ](https://blog.mamansoft.net/2019/02/01/review-vscode-vim-setting/#vim-indent-object) とか参考に
クリップボード,ハイライトサーチ,折りたたみ通過とか設定して終わり

```settings.json
    "vim.useSystemClipboard": true,
    "vim.hlsearch": true,
    "vim.foldfix": true,
```

# 設定まとめ

## plugin

https://marketplace.visualstudio.com/items?itemName=vscodevim.vim
https://marketplace.visualstudio.com/items?itemName=ryuta46.multi-command

## confings

<details><summary>settings.json</summary><div>

```settings.json
{
    "window.zoomLevel": 1,
    "vim.useSystemClipboard": true,
    "vim.hlsearch": true,
    "vim.foldfix": true,
    "multiCommand.commands": [
        {
            "command": "multiCommand.down4TextLines",
            "sequence": [
                "extension.vim_down",
                "extension.vim_down",
                "extension.vim_down",
                "extension.vim_down",
            ]
        },
        {
            "command": "multiCommand.down4ListLines",
            "sequence": [
                "list.focusDown",
                "list.focusDown",
                "list.focusDown",
                "list.focusDown"
            ]
        },
        {
            "command": "multiCommand.up4TextLines",
            "sequence": [
                "extension.vim_up",
                "extension.vim_up",
                "extension.vim_up",
                "extension.vim_up",
            ]
        },
        {
            "command": "multiCommand.up4ListLines",
            "sequence": [
                "list.focusUp",
                "list.focusUp",
                "list.focusUp",
                "list.focusUp"
            ]
        },
    ],
}
```
</div></details>

<details><summary>keybindings.json</summary><div>

```keybindings.json
// 既定値を上書きするには、このファイル内にキー バインドを挿入します
[
    {
        "key": "ctrl+f",
        "command": "-extension.vim_ctrl+f",
        "when": "editorTextFocus && vim.active && vim.use<C-f> && !inDebugRepl && vim.mode != 'Insert'"
    },
    {
        "key": "ctrl+j",
        "command": "extension.vim_escape",
        "when": "editorTextFocus && vim.active && !inDebugRepl"
    },
    {
        "key": "ctrl+j",
        "command": "-extension.vim_ctrl+j",
        "when": "editorTextFocus && vim.active && vim.use<C-j> && !inDebugRepl"
    },
    {
        "key": "ctrl+c",
        "command": "-extension.vim_ctrl+c",
        "when": "editorTextFocus && vim.active && vim.overrideCtrlC && vim.use<C-c> && !inDebugRepl"
    },
    {
        "key": "shift+h",
        "command": "cursorWordAccessibilityLeft",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+l",
        "command": "cursorWordAccessibilityRight",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+j",
        "command": "multiCommand.down4TextLines",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+j",
        "command": "multiCommand.down4ListLines",
        "when": "listFocus"
    },
    {
        "key": "shift+k",
        "command": "multiCommand.up4TextLines",
        "when": "editorTextFocus && vim.mode != 'Insert'"
    },
    {
        "key": "shift+k",
        "command": "multiCommand.up4ListLines",
        "when": "listFocus"
    },
]
```
</div></details>