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

概要
- 普段Neovimを使ってたけど、jupyterを使ってkaggleしたりするのでvscodeを使ってみてる
結局neovimに戻ってきた。(クライアントPCから編集するときだけvscode使ってる)
- keybindにはvscode neovimを使ってる
- Neovimのinit.luaはvscode用にvim.g.vscode使って設定を分岐させてる
分岐作って色々やるのが面倒になってVSCodeVimを使うことにしてる。設定をそれなりすればそれなりに動く。
init.vscode.lua作ってそっちに書くことにして VSCode Neovim に移行した。(2025/05)
-
ところどころvscodeと差分がでてるので解消したい
-
現状の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"
},
]
参考

補完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でパネルを移動する
- https://stackoverflow.com/a/50593160
- リンク先の設定を参考に設定
// 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"
}
]

vscodeにfuzzy finder
- vscode-neovimではtelescope使えないけど似た挙動でできる
- Neovimだと<C-p>でtelescope開くようにしてるけど、vscodeはcommand pallete開くから、とりあえずデフォルトのキーバインドで使う

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
これだけだと自分の設定では検索結果にフォーカスをキーバインドで当てれなかったらから設定を追加した
{
"key": "alt+m",
"command": "search.action.focusSearchList"
}

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"
}
},

semanticHighlightingはconfiguredByThemeにすればよかった

// -- 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",
}
参考:

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"
},

Explorer(filer)上でカーソル化にあるディレクトリ内にファイル/ディレクトリを作るのと相対パスをクリップボードにコピーするKeybindの設定
// -----
// --- make file/directory in explorer when explorer has focus
{
"key": "ctrl+e",
"command": "explorer.newFile",
"when": "explorerViewletVisible && filesExplorerFocus"
},
{
"key": "ctrl+n ctrl+d",
"command": "explorer.newFolder",
"when": "explorerViewletVisible && filesExplorerFocus"
},
// copy relative path of file/directory under cursor in explorer when explorer has focus
{
"key": "ctrl+y ctrl+y",
"command": "copyRelativeFilePath",
"when": "explorerViewletVisible && filesExplorerFocus"
},

Terminalにフォーカスがある時にパネルの最大化のトグルのキーバインド
{
// --- Maximize terminal panel
{
"key": "ctrl+m ctrl+t",
"command": "workbench.action.toggleMaximizedPanel",
"when": "terminalFocus"
}
}

VSCodeのbracket pair colorizationはめちゃ重いのでオフにした
{
"editor.bracketPairColorization.enabled": false
}

Markdownのtabsizeを指定. filetype毎に設定したいときは "[<file_type>]"以下のオブジェクトに書けばいいっぽい。
{
"[markdown]": {
"editor.tabSize": 2
}
}

stagingしてるdiffを元にkeybindでcopilotの生成したcommit messageでgit commit
- stagingの粒度を選べば勝手にcommit message作ってcommitする。
- commit messageを再生成したい時は
git reset HEAD^
が必要なので手間か?
[
{
// stageされてる内容をgit commitしてdiffを元にcommit messageを生成する
"key": "space g c m",
"command": "runCommands",
"args": {
"commands": [
"git.commit",
"github.copilot.git.generateCommitMessage",
"git.commitMessageAccept",
]
},
"when": "vim.mode == 'Normal' && !terminalFocus"
}
]
コマンド分けたversion. こっちのが使いやすかも。
[
/// Git AI generate commit message
///@desc: stageされてる内容をgit commitしてdiffを元にcommit messageをcopilotで生成する
/// {{{
{
"key": "ctrl+a m",
"command": "runCommands",
"args": {
"commands": [
{ "command": "workbench.action.toggleSidebarVisibility" },
{ "command": "git.viewStagedChanges" },
{ "command": "github.copilot.git.generateCommitMessage" },
{ "command": "workbench.action.focusSideBar" },
]
},
"when": "!sideBarVisible"
},
{
"key": "ctrl+a m",
"command": "runCommands",
"args": {
"commands": [
{ "command": "github.copilot.git.generateCommitMessage" },
{ "command": "git.viewStagedChanges" },
{ "command": "workbench.action.focusSideBar" },
]
},
"when": "sideBarVisible"
},
/// }}}
/// Git Commit
///@desc: commitを確定する
/// {{{
{
"key": "ctrl+g c",
"command": "runCommands",
"args": {
"commands": [
{ "command": "git.commitStaged" },
{ "command": "git.closeAllDiffEditors" }, // close git staged changed view
{ "command": "workbench.action.toggleSidebarVisibility" }, // close sidebar
{ "command": "workbench.action.terminal.focus" }, // 直前のフォーカスに戻る
]},
"when": "sideBarFocus && panelVisible"
},
{
"key": "ctrl+g c",
"command": "runCommands",
"args": {
"commands": [
{ "command": "git.commitStaged" },
{ "command": "git.closeAllDiffEditors" }, // close git staged changed view
{ "command": "workbench.action.toggleSidebarVisibility" }, // close sidebar
{ "command": "workbench.action.previousEditor" }, // 直前のフォーカスに戻る
]
},
"when": "sideBarFocus && !panelVisible"
},
/// }}}
]

CopilotChatでcommit messageをCOMMIT_EDITMSGに挿入する
- ~/.config/nvim/after/ftplugin/gitcommit.lua
- lazygitでC押してneovim開いてcommit message書いてもらってる
vim.schedule(function()
local chat = require("CopilotChat")
local commit_prompt = chat.prompts().Commit.prompt
chat.ask("> #git:staged\n\n" .. commit_prompt, {
callback = function(response, source)
-- code fenceでgitcommitで囲まれた部分を取得する
-- Extract content from the code fence
local lines = vim.split(response, "\n")
-- make commt message
local in_gitcommit_block = false
local commit_message = {}
for _, line in ipairs(lines) do
if line:match("^```gitcommit") then
in_gitcommit_block = true
elseif in_gitcommit_block then
if line:match("^```") then
in_gitcommit_block = false
else
table.insert(commit_message, line)
end
end
end
-- If no gitcommit block found, try to use the whole response
if #commit_message == 0 then
-- Skip code fences that aren't gitcommit blocks
vim.notify("No gitcommit block found, using whole response", vim.log.levels.WARN)
return response
end
if #commit_message > 0 then
vim.api.nvim_buf_set_lines(commit_bufnr, 0, 0, false, commit_message)
end
return response
end,
})
end)

macos限定だけど、一つのwindowにまとめる
- 便利。all you need is 系
- 画面の表示が若干狭くなるのがデメ
- tmuxのsessionみたいな感じ
{
"window.nativeTabs": true,
}
一つにまとめたwindowのスイッチをキーバインドで
- keybindings.jsonに以下を追記
{
{
"key": "alt+s",
"command": "workbench.action.switchWindow"
},
}