Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the disabling of the default keymaps #77

Closed
arnevm123 opened this issue Jun 11, 2024 · 7 comments
Closed

Allow the disabling of the default keymaps #77

arnevm123 opened this issue Jun 11, 2024 · 7 comments
Labels
enhancement New feature or request

Comments

@arnevm123
Copy link
Contributor

Problem to solve

Currently the default keymaps are always set. It would be nice to let the user decide if they want the default keymaps.

Proposal

Most plugins use a setup function that takes in a config, not sure what your vision on this would be, as ivy.nvim does not seem to have one as of now.

@arnevm123 arnevm123 added the enhancement New feature or request label Jun 11, 2024
@arnevm123
Copy link
Contributor Author

Hi @AdeAttwood, is this something you want implemented?
If so I can have a crack at it 😄 -

@AdeAttwood
Copy link
Owner

I am not completely opposed to this. I am not a fan of the hole setup function, I would be OK with exposing the register_backend function so it can be used. Then find a way to disable the default backends that get registered.

The main goal for this will be to maintain simple API with minimal configure options. I have some time this weekend, so I will get the test suite moved over to busted and get some better tests added for the register backend.

@arnevm123
Copy link
Contributor Author

arnevm123 commented Jun 15, 2024

Thanks!
For now I fixed this locally with this snippet:

vim.api.nvim_del_keymap("n", "<leader>p")
vim.api.nvim_del_keymap("n", "<leader>b")
vim.api.nvim_set_keymap("n", "<leader>p", '"+p', { noremap = true, silent = true })

And then I can also set new keymaps for Ivy itself with by making a ftplugin/ivy.lua in my config with a keymap like this:

vim.api.nvim_set_keymap(
	"n",
	"<esc>",
	"<cmd>lua vim.ivy.destroy()<CR>",
	{ noremap = true, silent = true, nowait = true }
)

@arnevm123
Copy link
Contributor Author

arnevm123 commented Jun 15, 2024

Also a quick question:
With telescope I was using the fzf mode, this would allow me to search for the file foo/bar/test.lua with a search string like fo ba te. With Ivy I have to search for fobate, as spaces will not give me the result.

I suppose I will just have to kick the habit of typing spaces while searching?

And thanks a lot for this plugin, it works like a charm and looks really good!

@AdeAttwood
Copy link
Owner

@arnevm123 I have done a sample of what I think this API could look like. I would appreciate you taking it for a spin and letting me know if it will do what you want it to. I don't know if you will need to disable the lazy loading of the plugin.

With telescope I was using the fzf mode, this would allow me to search for the file foo/bar/test.lua with a search string like fo ba te. With Ivy I have to search for fobate, as spaces will not give me the result.

Yea when I move over to rust I went for a fuzzy lib rather than the old cpp algo that was adapted to work more like fzf. Currently, the word boundary needs to be the same to be a match. So instead of using spaces, you can use / to get a higher match. If you have the string foo/bar/test.lua the pattern fo/ba/te will score higher than fobate because you have the /b and /t matching the word boundary.

@arnevm123
Copy link
Contributor Author

arnevm123 commented Jun 17, 2024

@AdeAttwood
I had a quick look and it seems like this does not work, as this now calls the setup twice, once at plugin/ivy.lua:20 and then a second time in my config.

---@param config IvySetupOptions
function ivy.setup(config)
  -- __AUTO_GENERATED_PRINT_VAR_START__
  print([==[ivy.setup config:]==], vim.inspect(config)) -- __AUTO_GENERATED_PRINT_VAR_END__
  print("ivy.setup")
  if has_setup then
    return
  end

  for _, backend in ipairs(config.backends) do
    register_backend(backend)
  end

  has_setup = true
end

Results in this:

ivy.setup config: {
  backends = { "ivy.backends.buffers", "ivy.backends.files", "ivy.backends.lines", "ivy.backends.lsp-workspace-symbols", "ivy.backends.rg" }
}
ivy.setup
ivy.setup config: {
  backends = { { "ivy.backends.files", {
        keymap = "<leader>fd"
      } } }
}
ivy.setup

I don't really see an easy way around this without exposing the setup function, but I can personally live with disabling and enabling keymaps 😄

Lazy loading did not really have an effect on this, as Lazy always loads the plugin which will always result in a call to the setup function. Once the code is loaded it calls the setup function.

@AdeAttwood
Copy link
Owner

@arnevm123, this one has been sorted in #81. I have also created a new ticket for the key map configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants