Open18

vscodeとNeovimの差分を減らすためのvscodeの設定用備忘録メモ

名無し。名無し。

概要

- 普段Neovimを使ってたけど、jupyterを使ってkaggleしたりするのでvscodeを使ってみてる

結局neovimに戻ってきた。(クライアントPCから編集するときだけvscode使ってる)

- keybindにはvscode neovimを使ってる
- Neovimのinit.luaはvscode用にvim.g.vscode使って設定を分岐させてる

分岐作って色々やるのが面倒になってVSCodeVimを使うことにしてる。設定をそれなりすればそれなりに動く。

  • ところどころvscodeと差分がでてるので解消したい

  • 現状のkeybindings.jsonは以下(差分が出てるのでそのうち更新したい)

keybindings.json
keybindings.json
// Place your key bindings in this file to override the defaultsauto[]
[
    {
        "key": "cmd+f cmd+j",
        "command": "python.execInTerminal"
    },
    {
        "key": "ctrl+t ctrl+j",
        "command": "workbench.action.terminal.focus"
    },
    {
        "key": "tab",
        "command": "selectNextQuickFix",
        "when": "editorFocus && quickFixWidgetVisible"
    },
    {
        "key": "shift+tab",
        "command": "selectPrevQuickFix",
        "when": "editorFocus && quickFixWidgetVisible"
    },
    {
        "key": "tab",
        "command": "selectNextSuggestion",
        "when": "editorTextFocus && suggestWidgetMultipleSuggestions && suggestWidgetVisible"
    },
    {
        "key": "shift+tab",
        "command": "selectPrevSuggestion",
        "when": "editorTextFocus && suggestWidgetMultipleSuggestions && suggestWidgetVisible"
    },
    {
        "key": "ctrl+w h",
        "command": "workbench.action.navigateLeft"
    },
    {
        "key": "ctrl+w l",
        "command": "workbench.action.navigateRight"
    },
    {
        "key": "ctrl+w k",
        "command": "workbench.action.navigateUp"
    },
    {
        "key": "ctrl+w j",
        "command": "workbench.action.navigateDown"
    },
    {
        "key": "ctrl+h",
        "command": "workbench.action.previousEditor",
    },
    {
        "key": "ctrl+l",
        "command": "workbench.action.nextEditor",
    },
    // ctrl + xでeditor(buffer)閉じる
    {
        "key": "ctrl+x",
        "command": "workbench.action.terminal.killEditor",
        "when": "terminalEditorFocus && terminalFocus && terminalHasBeenCreated && resourceScheme == 'vscode-terminal' || terminalEditorFocus && terminalFocus && terminalProcessSupported && resourceScheme == 'vscode-terminal'"
    },
    {
        "key": "ctrl+w",
        "command": "-workbench.action.terminal.killEditor",
        "when": "terminalEditorFocus && terminalFocus && terminalHasBeenCreated && resourceScheme == 'vscode-terminal' || terminalEditorFocus && terminalFocus && terminalProcessSupported && resourceScheme == 'vscode-terminal'"
    },
    {
        "key": "ctrl+x",
        "command": "workbench.action.closeActiveEditor"
    },
    {
        "key": "ctrl+w",
        "command": "-workbench.action.closeActiveEditor"
    },
    {
        "key": "tab",
        "command": "selectNextQuickFix",
        "when": "editorFocus && quickFixWidgetVisible"
    },
    {
        "key": "shift+tab",
        "command": "selectPrevQuickFix",
        "when": "editorFocus && quickFixWidgetVisible"
    },
    {
        "key": "tab",
        "command": "selectNextSuggestion",
        "when": "editorTextFocus && suggestWidgetMultipleSuggestions && suggestWidgetVisible"
    },
    {
        "key": "shift+tab",
        "command": "selectPrevSuggestion",
        "when": "editorTextFocus && suggestWidgetMultipleSuggestions && suggestWidgetVisible"
    },
    {
        "key": "shift+q",
        "command": "editor.action.showHover",
        "when": "editorTextFocus"
    },
    {
        "key": "alt+m",
        "command": "search.action.focusSearchList"
    },
]

参考

  1. https://code.visualstudio.com/docs/getstarted/userinterface
  2. https://code.visualstudio.com/docs/getstarted/keybindings
名無し。名無し。

補完windowで候補を選択する時にtabを押すと候補が選ばれてしまう

  • Neovimだとtab/Shift+tabで候補を選んで、Enterで決定するように設定してた
  • https://blog.lanzani.nl/2016/tab-in-vscode/
  • 上のリンク先にある設定をkeyに設定するとtab/Shift+tabで候補を選べるようになった
名無し。名無し。

補完windowで候補選択時に関数等はdocstringとかを横に表示してほしい

  • Neovimだと候補選択時に、候補の横にdocstringを自動で表示するようにpluginを入れてた
  • vscodeだとでてなかった
  • 設定のsuggest:Show Inline Detailsのチェックを外すと出るようになった
  • この辺?https://github.com/microsoft/vscode/issues/18582
名無し。名無し。

Ctrl + w, h/j/k/lでパネルを移動する

// ctrl + h/j/k/lでパネルを移動
// Reference: https://stackoverflow.com/a/50593160
[
    {
        "key": "ctrl+w h",
        "command": "workbench.action.navigateLeft"
    },
    {
        "key": "ctrl+w l",
        "command": "workbench.action.navigateRight"
    },
    {
        "key": "ctrl+w k",
        "command": "workbench.action.navigateUp"
    },
    {
        "key": "ctrl+w j",
        "command": "workbench.action.navigateDown"
    }
]
名無し。名無し。

Ctrl + h/lでEditor移動

// ctrl + h/lでeditor移動する(Neovimのbuffer移動)
[
    {
        "key": "ctrl+h",
        "command": "workbench.action.previousEditor",
    },
    {
        "key": "ctrl+l",
        "command": "workbench.action.nextEditor",
    }
]
名無し。名無し。

Ctrl + xでeditor(buffer)を閉じる

[
// ctrl + xでeditor(buffer)閉じる
    {
        "key": "ctrl+x",
        "command": "workbench.action.terminal.killEditor",
        "when": "terminalEditorFocus && terminalFocus && terminalHasBeenCreated && resourceScheme == 'vscode-terminal' || terminalEditorFocus && terminalFocus && terminalProcessSupported && resourceScheme == 'vscode-terminal'"
    },
    {
        "key": "ctrl+w",
        "command": "-workbench.action.terminal.killEditor",
        "when": "terminalEditorFocus && terminalFocus && terminalHasBeenCreated && resourceScheme == 'vscode-terminal' || terminalEditorFocus && terminalFocus && terminalProcessSupported && resourceScheme == 'vscode-terminal'"
    },
    {
        "key": "ctrl+x",
        "command": "workbench.action.closeActiveEditor"
    },
    {
        "key": "ctrl+w",
        "command": "-workbench.action.closeActiveEditor"
    }
]
名無し。名無し。

hoverをkeyboardで出す

  • Neovimでの設定と合わせるのにshift + qでhoverで型情報を出す
{
        "key": "shift+q",
        "command": "editor.action.showHover",
        "when": "editorTextFocus && vim.mode == 'Normal'"
}
名無し。名無し。

vscode組み込みのfuzzy searchを使う

下のリンク先を参考にコマンドを定義する。これで<Leader>rgでサイドバーの検索にフォーカスがあたる. echol mapleader'してundefinedなら設定はデフォルトなのでleaderキーは`

local keymap = vim.api.nvim_set_keymap
local function notify(cmd)
    return string.format("<cmd>call VSCodeNotify('%s')<CR>", cmd)
end

keymap('n', '<Leader>rg', notify 'workbench.action.findInFiles', { silent = true }) -- use ripgrep to search files

https://github.com/milanglacier/nvim/blob/f54b7356dc97cbf9b07a77d5db1ad199c2ff3f2e/lua/conf/vscode.lua#LL31

これだけだと自分の設定では検索結果にフォーカスをキーバインドで当てれなかったらから設定を追加した

{
  "key": "alt+m",
  "command": "search.action.focusSearchList"
}

https://stackoverflow.com/questions/59677329/visual-code-key-shortcut-navigate-search-sidebar

名無し。名無し。

Vscode Neovimが時々動作しなくなるので公式のemulatorに乗り換えてみた

Cursorが点滅するのを直す

{
  "editor.cursorBlinking": "solid"
}
名無し。名無し。

tokenの色つけの数を増やす(treesitterっぽい?token数になる)

  "editor.semanticHighlighting.enabled": true,
名無し。名無し。

semanticHighlightingするとpythonの変数の宣言がfor statementと同じ色で見分けがつきにくい

vscodeのtokyonightのsemanticHighlightingだと見分けがつきにくい。
tokenの色付けを上書きして、他の部分と同じ色付けに変える

  "editor.semanticTokenColorCustomizations": {
    "rules": {
      "variable.declaration": "#c0caf5"
    }
  },
名無し。名無し。
// -- Copilot
// insert inline seggestion in insert mode by ctrl+g
{
    "key": "ctrl+g",
     "command": "editor.action.inlineSuggest.commit",
     "when": "vim.mode == 'Insert'",
},
名無し。名無し。

LineNumber表示してるカラムがデカすぎなので小さくする

{
    "editor.glyphMargin": false, // to be tight of the line number column
    "editor.folding": false, // to be tight of the line number column
}
名無し。名無し。

横のActivityBarが邪魔なので見えなくする

{
    "workbench.activityBar.visible": false,
}

上の設定はdeprecateになってるっぽい。下の設定にする。

{
  "workbench.activityBar.location": "hidden",
}

これで見えなくなる。みたい時はcommand palleteからActivityBarをtoggleすればいい

今は、"top"にしてる。これだと横を広く使いながらうまく共存できる気がしてる。

{
  "workbench.activityBar.location": "top",
}

参考:

https://qiita.com/tomoasleep/items/fcab2110b6fe03c809e4

名無し。名無し。

SideBarにある全文検索の設定

VSCodeVimのNormalモードでターミナルにフォーカスがない時、<C-/> で全文検索に入る。telescopeでいうところのGrep。<C-/> で検索にフォーカスが当たった後、検索結果にフォーカスする時には<C-w j>を押す。もう一度、検索窓にフォーカスを当てたい時には<C-w k>

    // -- 全文検索
    {
        "key": "ctrl+/",
        "command": "workbench.action.findInFiles",
        "when": "vim.mode == 'Normal' && !terminalFocus || !terminalEditorFocus"
    },
    {
        "key": "ctrl+w j",
        "command": "search.action.focusSearchList",
        "when": "sideBarFocus && searchViewletVisible && !terminalFocus || !terminalEditorFocus"
    },
    {
        "key": "ctrl+w k",
        "command": "workbench.action.findInFiles",
        "when": "sideBarFocus && searchViewletVisible && !terminalFocus || !terminalEditorFocus"
    },