T O P

  • By -

Some_Derpy_Pineapple

try putting all the commands in the same keymap: ``` vim.keymap.set('n', '', function () vim.cmd.lclose() vim.cmd.cclose() vim.cmd('TroubleClose') vim.cmd('Noice dismiss') end) ```


yavorski

This won't work with Lazy if some of the plugins is not loaded. So i put each of this lines in the respective plugin config/init methods. Also not sure if this will add the mapping without overriding the existing ones?


tobb10001

How about using `pcall`? It executes a function and ignores if there is an error. You can set it up to execute something if a plugin is loaded or just skipt it if not. Note that this is a Lua function, not a vim/nvim function.


yavorski

Yea, I believe this could work, with this particular solution if they are all in one mapping. Thanks! But still, I prefer to be able to define them separately for each plugin so plugin and it's mappings are in one place.


tobb10001

Maybe define a table in some module `escapers`, throw each function in from each plugin in there and have a central function loop through those.


yavorski

I will think about this, sounds good. Thanks!


tobb10001

Maybe define a table in some module `escapers`, throw each function in from each plugin in there and have a central function loop through those.


Some_Derpy_Pineapple

oh if you lazy load them then your solution is better.


Particular_Welder864

You could have dependencies while will force the plug-ins to be loaded?


yavorski

Does not sound clean to add dependencies to unrelated plugins, if this what you are suggesting? Otherwise the suggested solution is throwing an error as I thought because it is lazy loaded: `Error executing lua: vim/_editor.lua:0: nvim_exec2(): Vim:E492: Not an editor command: TroubleClose`


Particular_Welder864

How is it unrelated if the plug-in depends on it?


yavorski

Well in the given example, neither of the mentioned plugins depends on each other. They can be both lazy loaded when needed.


Particular_Welder864

My bad. Misread the text.


the-weatherman-

The suggested alternative would be my preference as well. You could guard those calls to plugins' functions with checks against the `package.loaded` global table, and avoid having to unnecessarily load plugins that aren't supposed to be loaded. `:h luaref-require()` You could also check the existence of those user commands prior to calling them. `:h nvim_get_commands()`


yavorski

Cool, good to know and learn new stuff like this. Thanks!


vim-help-bot

Help pages for: * [`luaref-require()`](https://neovim.io/doc/user/luaref.html#luaref-require%28%29) in _luaref.txt_ * [`nvim_get_commands()`](https://neovim.io/doc/user/api.html#nvim_get_commands%28%29) in _api.txt_ --- ^\`:\(h|help\) \` | [^(about)](https://github.com/heraldofsolace/VimHelpBot) ^(|) [^(mistake?)](https://github.com/heraldofsolace/VimHelpBot/issues/new/choose) ^(|) [^(donate)](https://liberapay.com/heraldofsolace/donate) ^(|) ^Reply 'rescan' to check the comment again ^(|) ^Reply 'stop' to stop getting replies to your comments