FeiyouG / commander.nvim

Create and manage keybindings and commands in a more organized manner, and search them quickly through Telescope

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Reload on config source

axkirillov opened this issue · comments

Hi! I noticed that when I source my init.vim after changing something in the config the changed command will get appended to the list instead of replaced.
So for example, I have these set up

command_center.add({
	{
		description = "Show changed files",
		cmd = "<CMD>Telescope changed_files<CR>",
	},
	{
		description = "Edit init.vim",
		cmd = "<CMD>:e $CONFIG/nvim/init.vim<CR>",
	},
	{
		description = "Source init.vim",
		cmd = "<CMD>:source $CONFIG/nvim/init.vim<CR>",
	},
	{
		description = "Delete all buffers",
		cmd = "<CMD>:%bd|e#<CR>",
	},
})

if I change something, for example

command_center.add({
	{
		description = "I CHANGED THIS COMMAND",
		cmd = "<CMD>Telescope changed_files<CR>",
	},
	{
		description = "Edit init.vim",
		cmd = "<CMD>:e $CONFIG/nvim/init.vim<CR>",
	},
	{
		description = "Source init.vim",
		cmd = "<CMD>:source $CONFIG/nvim/init.vim<CR>",
	},
	{
		description = "Delete all buffers",
		cmd = "<CMD>:%bd|e#<CR>",
	},
})

and then run :source %, this is what I get:
image

Thanks for bring this to my attention. I will look into this once I get some time this week. It should be an easy fix.

After thinking about it more carefully, I don't think this can be accomplished.

If we want command_center to update the description of a command at runtime, then we will have to use cmd as the key so that we can find the command. However, what if we updated cmd at runtime but didn't change the description? Intuitively, we still want command_center to only update the desc of the corresponding cmd, instead of adding a new entry. But we can't achieve it if cmd is used as the key.

I think implement this will lead to even more confusing, unless I can come up with a beffer solution to id each command. I will mark this as won't fix, but please let me know if you have any good ideas.

I see. I would like to have a setup() function where I can specify all of my commands and then on each call of this function the entire command set will be overwritten / created a new. To me that would be a more intuitive and neovim-like workflow. Let me know what you think.

That makes sense. However, we have to come up with a new set of APIs with sensible names to accomplish this, so that introducing this feature will not break anyone's current workflow. I need some time to think about this. And please let me know or submit a PR if you have some good ideas.

I have a new idea and I'd like to hear your thoughts on this:

What about we have a new field called id. If it is not specified when a command is added , then nothing happens and everything behaves as it would before. However, if it is set, then the next time when a new command with the same id is added, the new command will replace the old one.

To make things easier, we can also allow the user to set a pattern for id in opts, so that you don't have to manually set id for each command. For example:

command_center.add({
  {
    desc = "description",
    cmd = "<cmd>Telescope command_center<cr>",
    keys = ...
  }, {
   ...
  }
}, {
  cat = "lsp", 
  ...
  id = "$cmd" .. "$desc"  -- Will use each command's cmd + desc as its id
})

Hi! Sorry for late reply, but I don't use this plugin anymore. You can close the issue, if you want 🙂

FYI This commit added commander.clear() API which may help with your use case.