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

[Feature]: Load keymaps from Neovim API #258

Open
1 task done
mrjones2014 opened this issue Dec 13, 2022 · 8 comments
Open
1 task done

[Feature]: Load keymaps from Neovim API #258

mrjones2014 opened this issue Dec 13, 2022 · 8 comments
Assignees
Labels
enhancement New feature or request PRs-welcome I'd love to see a PR for this

Comments

@mrjones2014
Copy link
Owner

Similar Issues

  • Before filing, I have searched for similar issues.

Description

Automatically load existing keymaps via vim.api.nvim_get_keymap(mode).

For additional context see #39

@mrjones2014
Copy link
Owner Author

If anyone wants to work on a PR here are some specific points I'd like to include in the implementation:

  • Duplicate filtering -- don't register or apply keymaps that are already applied via legendary.nvim config
  • Provide an API to load keymaps from the Neovim API, and also provide a boolean option in legendary.nvim config that loads them on require('legendary').setup()

@ehaynes99
Copy link

Heh, I was just coming to see if this had been filed before. I'm a little swamped right now, but might be able to look into in a few weeks.

This won't work in setup(), though. It would need to wait until called on a buffer, or it will be missing any mapping added after legendary setup was run. Personally, I don't set any keymaps until after all of the plugin configurations are complete, as I reference various plugins in the bindings (the lazy functions in toolbox attempt to work around this problem, but it's not an issue if you simply wait). This would also miss any dynamic bindings like those added by the lsp on_attach handlers. It could potentially cache the list by buffer id after the first time it's called for any particular buffer, but I'm not sure if anyone is doing even more dynamic mappings based on autocommands.

The telescope implementation of this does it on the fly every time without any noticeable delay.

@hinell
Copy link
Contributor

hinell commented Feb 2, 2023

The help index.txt is a good starting point I guess.

@mrjones2014
Copy link
Owner Author

@ehaynes99 I'd love to see a PR for this if you're still interested 🙂

@mrjones2014 mrjones2014 added the PRs-welcome I'd love to see a PR for this label May 18, 2023
@lougreenwood
Copy link

Just adding a note here that this seems to be the reason why neo-tree mappings (including opening and toggling neo tree) don't appear.

It seems that neo-tree uses nui to set it's mappings and nui uses vim.api.nvim_buf_set_keymap.

Not sure I have the skills or time to tackle this, but maybe I'll find the time if the pain gets high enough 😅 .

@mrjones2014
Copy link
Owner Author

Copying my comment from the linked issue here for documentation purposes:

Just jumping in here from the linked issue:

although it currently doesn't surface actual commands, see #39

You can define commands with legendary or load them into legendary, but it doesn't do it automatically for a few reasons. For commands coming from plugins, it should be pretty straightforward to write a legendary extension, there's a few bulit-in ones you can use as an example. They can be written in the upstream plugin repo, or as a PR to legendary itself.

@lougreenwood for example, neo-tree seems like it could have a legendary extension written for it, by mapping the action names from the neo-tree config to a description like

local descriptions = {
  navigate_up = 'Navigate up',
  order_by_git_status = 'Sort by git status',
  -- ... the rest here
}

And then converting the keymap definitions into the right format. Example: lazy.nvim legendary extension.

@lougreenwood
Copy link

Thanks @mrjones2014, however, it seems that if I were to try this, then effort spent creating a neo-tree extension would be better spent improving legendary so that it can import all mappings set using the vim api? WDYT?

@mrjones2014
Copy link
Owner Author

Yeah, at this point in time it should be possible to load keymaps from the vim.* API, however for some plugin mappings you might lose context doing it that way (for example, plugins like neo-tree that have mappings only in that specific buffer. some legendary extensions handle this based on filetype or buftype).

Loading commands, however, remains roadblocked (see the conversation in #39) because weirdly the desc field of the commands returned from the API is not reliably a description -- if no description was provided, the field will be the implementation of the command which could be a long ugly string of Lua or Vimscript code, which isn't really what we'd want to show in legendary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PRs-welcome I'd love to see a PR for this
Projects
None yet
Development

No branches or pull requests

4 participants