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: Add option to disable all LazyVim keymaps #238

Closed
1 task done
MaazSiddiqi opened this issue Feb 11, 2023 · 9 comments · Fixed by #239
Closed
1 task done

feature: Add option to disable all LazyVim keymaps #238

MaazSiddiqi opened this issue Feb 11, 2023 · 9 comments · Fixed by #239
Labels
enhancement New feature or request

Comments

@MaazSiddiqi
Copy link

MaazSiddiqi commented Feb 11, 2023

Did you check the docs?

  • I have read all the LazyVim docs

Is your feature request related to a problem? Please describe.

It's really frustrating when reassigning keymaps, and you want to map say <leader>f, but somewhere there's a map for <leader>fr. Of course, you don't initially know an fr key bind exists, so whenever you do <leader>f, nvim is pending for another keystroke before confirming the call...I think. So you have to hunt for any <leader>f{char} keymaps and unbind them, or even worse, have to reassign them.

I love how LazyVim ships with a great set of default bind. However, as someone who's built strong preferences for their keymaps, it can make the process of reassigning binds frustrating and tedious.

Describe the solution you'd like

I would love it if there was a way to just not load any of the default keymaps at all. Give the user the option to fully reconfigure their key binds from scratch, or let them start off with a much smaller subset of key binds, and provide the rest as opt-ins. This would be similar to how we approach lazyvim.plugins.extras.lang.typescript but instead of language extensions, we have keymap extensions.

As someone migrating with a preconfigured list of keymaps, this would simplify the process for me a lot more. We can enable it through the main lazy.lua file:

require("lazy").setup({
  spec = {
    -- add LazyVim and import its plugins
    { "LazyVim/LazyVim", import = "lazyvim.plugins", keys = false },

Keymap extensions aren't necessary, but it would be great if LazyVim had a way to disable importing its default keymaps. Then I can use the same principle of adding keymaps to my plugins inside spec files keymaps.lua and they'd just get merged like normal.

Describe alternatives you've considered

Going into each separate plugin and disabling keys that are conflicting or making neovim wait.

Additional context

Sorry if the issue is too wordy, I'm not too used to writing issues yet. Also, I've tried adding keys = function () return {} end to the lazyVim spec, but keymaps were still getting loaded. If this is already implemented, am I doing it the wrong way?

@MaazSiddiqi MaazSiddiqi added the enhancement New feature or request label Feb 11, 2023
@folke folke closed this as completed in 6669e63 Feb 11, 2023
@folke
Copy link
Collaborator

folke commented Feb 11, 2023

Made this configurable. See https://www.lazyvim.org/configuration#default-settings

@Nohac
Copy link

Nohac commented Feb 11, 2023

@folke Will this new setting also disable default keymaps for telescope and lsp? If not, I think it would be great to have, or at least add separate options for those.

I'm currently trying to remap some lsp bindings following this documention, but it doesn't seem to work, for example, remapping code action:

{
    "neovim/nvim-lspconfig",
    init = function()
      local keys = require("lazyvim.plugins.lsp.keymaps").get()

      keys[#keys + 1] = { "<leader>ca", false }
      keys[#keys + 1] =
        { "C-s", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }
}

In this example, <leader>ca doesn't get disables, and C-s does nothing.
I think having an "opt out" option for all mappings could make this process a lot easier.

@dpetka2001
Copy link
Contributor

dpetka2001 commented Feb 11, 2023

You forgot end to close the function. I just tried your example and the specific keymap works for me.

{
    "neovim/nvim-lspconfig",
    init = function()
      local keys = require("lazyvim.plugins.lsp.keymaps").get()
      keys[#keys + 1] =
        { "<C-s>", vim.lsp.buf.code_action, desc = "Code Action", mode = { "n", "v" }, has = "codeAction" }
    end,
}

@folke
Copy link
Collaborator

folke commented Feb 11, 2023

@Nohac you can already disable default key bindings for plugins. It's in the docs.

@MaazSiddiqi
Copy link
Author

MaazSiddiqi commented Feb 12, 2023

@folke, @Nohac's suggestion reminds me that there are still keymaps from plugins that get mapped too on init. Intuitively, when I tell LazyVim to not load any default keymaps, I'd expect a clean slate of keymaps, but here the plugins still get initialized with binds attached. This isn't as much of an issue for me, but it still only half solves the initial problem of conflicting remaps.

You could still disable keymaps per plugin that you find conflicting. However, the intention of not loading defaults is that the user has a clean slate to add mappings on top of. Currently, the user can work top-down, deleting any keymaps and/or disabling/overwriting plugins you don't need. However, some users who have really minimal setups may want to work bottom-up, starting from the bare basics while still taking advantage of all the lazyloading and other features LazyVim provides. You can certainly disable all the plugins you don't need, but say I only wanted telescope and cmp, I'd have to manually disable EVERY other plugin that ships with LazyVim, which certainly adds up and could get outdated if we decide to include more plugins in the future.

I can suggest a way to handle this in the context of keymaps at least. For all keymaps that are assigned in the framework, just use a wrapper map function that includes a guard clause for !config.defaults.keymaps and voids the map call.

In the context of plugins, I can suggest extending opts.defaults with plugins = false. Now, LazyVim won't load the default set of additional plugins. In spec files, the user can enable a plugin, and if LazyVim already has a preconfigured config for that plugin, it will follow normal merging rules. To add more control on top of plugins = false, you could extend with:

plugins = {
  coding = true,
  editor = true,
  ui = true,
  ...
}

This will let users still load subsets of plugins, and have a smaller amount of plugins to remove if they so choose. I'm not too familiar with the code for LazyVim, so I don't truly know the complexity of the implementation, but it's a suggestion.

Overall, this will allow this recommendation would allow users to build bottom-up. The question is whether this is something that aligns with LazyVim's philosophy of convenience (since it's so manual, is it really "lazy" anymore). Users will still be inclined to use LazyVim though due to its lazyloading and compact UI and preconfigured plugins, they will just have more freedom in choosing exactly which set of plugins to enable from the core.

Would love to hear your thoughts!

@folke
Copy link
Collaborator

folke commented Feb 12, 2023

If you don't want any of the keymaps for the plugins loaded as well, then you probably shouldn't be using LazyVim. I'm not going to add any additional ways to disable plugin keymaps. You can already do that right now.

@egolep
Copy link

egolep commented Mar 11, 2023

Made this configurable. See https://www.lazyvim.org/configuration#default-settings

Sorry, probably stupid question: I don't get how to use this in my custom config. Should I create a lua file and add this configurations (as I do for plugins) or I should create a specific file inside my config folder? Or should I edit the specific file inside LazyVim's config files?

@MaazSiddiqi
Copy link
Author

@egolep you can edit the LazyVim spec like you would change a color scheme, by editing opts.

In a spec file under lua/plugins/, add the following:

return {
  {
    "LazyVim/LazyVim",
    opts = {
        defaults = {
            autocmds = true, -- lazyvim.config.autocmds
            keymaps = true, -- lazyvim.config.keymaps
            options = true, -- lazyvim.config.options
      },
    }
  }
}

@egolep
Copy link

egolep commented Mar 17, 2023

@egolep you can edit the LazyVim spec like you would change a color scheme, by editing opts.

In a spec file under lua/plugins/, add the following:

return {
  {
    "LazyVim/LazyVim",
    opts = {
        defaults = {
            autocmds = true, -- lazyvim.config.autocmds
            keymaps = true, -- lazyvim.config.keymaps
            options = true, -- lazyvim.config.options
      },
    }
  }
}

Thanks man!
Sorry, in retrospective it looks obvious.

ofrades pushed a commit to ofrades/LazyVim that referenced this issue May 30, 2023
joshmedeski pushed a commit to joshmedeski/LazyVim that referenced this issue Sep 1, 2023
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

Successfully merging a pull request may close this issue.

5 participants