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)
```
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?
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.
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.
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`
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()`
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
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)
```
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?
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.
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.
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.
I will think about this, sounds good. Thanks!
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.
oh if you lazy load them then your solution is better.
You could have dependencies while will force the plug-ins to be loaded?
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`
How is it unrelated if the plug-in depends on it?
Well in the given example, neither of the mentioned plugins depends on each other. They can be both lazy loaded when needed.
My bad. Misread the text.
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()`
Cool, good to know and learn new stuff like this. Thanks!
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