dotfiles
dotfiles copied to clipboard
Issues loading nvim plugins conditionally when using VSCode
I use vscode-neovim which uses neovim as a backend so it uses the regular nvim config as well. However, I don't want some plugins (eg. the catppuccin colorscheme) to be loaded when running VSCode. I'm using packer for plugin management so I use the cond
attribute to load them conditionally eg. here:
cond = 'vim.fn.empty(vim.g.vscode) == 1',
This works well when a plugin is stand-alone and has no dependencies. However, when a plugin has dependencies it gets trickier. Dependencies are specified using the requires
attribute eg. telescope depends on plenary.nvim so specifying it in the requires
block of Telescope automatically installs it when Telescope is installed without requiring a separate use
spec. However, while Telescope itself has a cond
attribute which loads it only when running neovim, since plenary doesn't have its own use
spec, there's nothing which makes it load conditionally and thus it gets loaded even when running VSCode. Plenary itself is benign and it wouldn't be too bad to let it load even when running VSCode. However, other plugins eg. lsp, cmp etc. have dependencies which throw errors when running VSCode.
I tried adding the same cond
attribute to the dependency as well and it worked for Telescope and Plenary but it failed for other plugins such as lsp and cmp. Looks like there's a bug in Packer with how it handles conditional dependencies.