AdeAttwood / ivy.nvim

An ivy-mode port to neovim.
35 stars 4 forks source link

Allow the disabling of the default keymaps #77

Closed arnevm123 closed 4 months ago

arnevm123 commented 4 months ago

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 commented 4 months ago

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

AdeAttwood commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

@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 commented 4 months ago

@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 :smile:

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 commented 4 months ago

@arnevm123, this one has been sorted in https://github.com/AdeAttwood/ivy.nvim/pull/81. I have also created a new ticket for the key map configuration.