I'm using Neovim with lazy.nvim
as my plugin manager and the vscode-neovim
extension in VSCode. I've configured my custom keymap in my vscode.lua
file but they only work when I'm in text buffers. These keymap don't function in VSCode's welcome or setting pages for example.
Here's my vscode.lua
config:
if not vim.g.vscode then
return {}
end
local enabled = {
"lazy.nvim",
"mini.move",
"mini.surround",
"nvim-treesitter",
"yanky.nvim",
"sqlite.lua",
}
local Config = require("lazy.core.config")
Config.options.checker.enabled = false
Config.options.change_detection.enabled = false
Config.options.defaults.cond = function(plugin)
return vim.tbl_contains(enabled, plugin.name) or plugin.vscode
end
vim.api.nvim_create_autocmd("User", {
pattern = "VscodeNeovimKeyMaps",
callback = function()
vim.keymap.set("n", "<leader>P", "<cmd>Find<cr>")
vim.keymap.set("n", "<leader>/", [[<cmd>call VSCodeNotify('workbench.action.findInFiles')<cr>]])
vim.keymap.set("n", "<leader>ss", [[<cmd>call VSCodeNotify('workbench.action.gotoSymbol')<cr>]])
vim.keymap.set("v", "<leader><space>", [[<cmd>call VSCodeNotify('whichkey.show')<cr>]])
vim.keymap.set("n", "<leader><space>", [[<cmd>call VSCodeNotify('whichkey.show')<cr>]])
vim.keymap.set("n", "<leader>ff", [[<cmd>call VSCodeNotify('binocular.searchFileConfiguredFolders')<cr>]]) -- Search by file name
vim.keymap.set("n", "<leader>fd", [[<cmd>call VSCodeNotify('binocular.searchDirectoryConfiguredFolders')<cr>]]) -- Search by directory name
vim.keymap.set("n", "<leader>fg", [[<cmd>call VSCodeNotify('binocular.searchFileHistory')<cr>]]) -- Search file history
end,
})
return {
{
"folke/lazy.nivm",
config = function(_, opts)
opts = opts or {}
end,
},
{
"nvim-treesitter/nvim-treesitter",
opts = { highlight = { enable = false } },
},
}
I tried to use keybindings.json
in VSCode to send the key to Neovim but seems like it didn't work.
I expect the key to work consistently across VSCode, I mean when I'm not in text buffers. Any suggestion would be greatly appreciated
OS: Windows (WSL2)
Neovim version: NVIM v0.11.0-dev-487+gc025c049a
i just discovered that I only need to use the keybindings.json file in vscode for it to work outside of text buffers
{
"key": "space shift+p",
"command": "workbench.action.quickOpen",
"when": "!editorTextFocus && !inputFocus"
},
{
"key": "space space",
"command": "whichkey.show",
"when": "!editorTextFocus && !inputFocus"
},
{
"key": "space f f",
"command": "binocular.searchFileConfiguredFolders",
"when": "!editorTextFocus && !inputFocus"
},
{
"key": "space f d",
"command": "binocular.searchDirectoryConfiguredFolders",
"when": "!editorTextFocus && !inputFocus"
},
{
"key": "space f g",
"command": "binocular.searchFileHistory",
"when": "!editorTextFocus && !inputFocus"
}
you can looks at my keybindings.json here for more info