1

In neovim, I have my leader mapped to space.

I also use nvim-tree.

What I want: when nvim-tree is open and that is the active buffer (cursor is there), map leader to something else so I can use space to expand folders in the tree. This feels most natural to me.

Is there a way to do this? Seems like it'd be useful broadly to have environment dependent keymaps

4
  • You can always use <localleader> with <buffer>-specific mappings.
    – D. Ben Knoble
    Jan 3, 2023 at 19:10
  • Thanks! I'll give that a try
    – echo
    Jan 4, 2023 at 13:51
  • I think I got it working
    – echo
    Jan 4, 2023 at 13:54
  • please post an answer if you solved your problem
    – D. Ben Knoble
    Jan 4, 2023 at 21:04

1 Answer 1

0

In require("nvim-tree").setup(), add the space key (or any key) as an 'edit' keymap and it'll automatically override other mappings to that key when in the tree context. I thought I'd have to manually configure this but it just works out of the box:

  view = {
    ...
    mappings = {
      ...
      list = {
        { key = {" ", "<other edit keys>"}, cb = tree_cb("edit") },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.