3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

私的VSCodeでのVim設定

Last updated at Posted at 2020-03-15

長い間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 を導入していないとできない気がするので導入

コマンドパレットから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"
    },

その他

ココ とか参考に
クリップボード,ハイライトサーチ,折りたたみ通過とか設定して終わり

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

settings.json
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"
            ]
        },
    ],
}
keybindings.json
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"
    },
]
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?