How to Change nvim-tree's "s" Keymap to "ss" in Neovim and Issues with Disabling "s" Keymap?

571 Views Asked by At

How to Change nvim-tree's "s" Keymap to "ss" in Neovim and Issues with Disabling "s" Keymap?

I'm working with the nvim-tree plugin in Neovim and am trying to change the default keymap for opening the system file viewer from "s" to "ss". I've attempted the following steps, but haven't been successful yet:

  1. I tried to unmap the original "s" key by using:

    vim.api.nvim_set_keymap("n", "s", "<nop>", {noremap = true, silent = true})
    
  2. Then, I tried to set up a custom attachment function to map "ss" to the desired action:

    local function my_on_attach(bufnr)
      local api = require "nvim-tree.api"
    
      local function opts(desc)
        return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true }
      end
    
      -- default mappings
      api.config.mappings.default_on_attach(bufnr)
    
      -- custom mappings
      vim.keymap.del("n", "s")
    end
    
    -- pass to setup along with your other options
    require("nvim-tree").setup {
      ---
      on_attach = my_on_attach,
      ---
    }
    

Despite these attempts, the "s" key is still performing its original action, and I haven't been able to map "ss" to the function that "s" was performing. I also encountered an error when trying to modify the nvim-tree settings directly, as it mentioned "Unknown option: view.mappings".

Can anyone advise me on what I might be doing wrong or what I should do to successfully remap "s" to "ss" in nvim-tree and disable the original "s" keymap?

0

There are 0 best solutions below