stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.36k stars 91 forks source link

bug: Unable to remap keymaps #418

Closed exosyphon closed 2 weeks ago

exosyphon commented 3 weeks ago

Did you check the docs and existing issues?

Neovim version (nvim -v)

NVIM v0.10.0

Operating system/version

MacOS 14.4

Describe the bug

When I try to remap with another keybind it doesn't seem to take and it won't show on the help screen.

What is the severity of this bug?

tolerable (can work around it)

Steps To Reproduce

Add this config, try to use H to open a horizontal split and see that nothing happens. Open help and see that H does not have any description text.

{
    "stevearc/oil.nvim",
    opts = {},
    dependencies = { "nvim-tree/nvim-web-devicons" },
    config = function()
      require("oil").setup({
        default_file_explorer = true,
        delete_to_trash = true,
        skip_confirm_for_simple_edits = true,
        view_options = {
          show_hidden = true,
          natural_order = true,
          is_always_hidden = function(name, _)
            return name == ".." or name == ".git"
          end,
        },
        win_options = {
          wrap = true,
        },
        use_default_keymaps = false,
        keymaps = {
          ["<leader>H"] = { "actions.select", opts = { horizontal = true } },
          ["<C-c>"] = false,
          ["q"] = "actions.close",
          ["g?"] = "actions.show_help",
          ["<CR>"] = "actions.select",
          ["<C-s>"] = { "actions.select", opts = { vertical = true } },
          ["<C-h>"] = false,
          ["<C-t>"] = { "actions.select", opts = { tab = true } },
          ["<C-p>"] = "actions.preview",
          ["<C-l>"] = "actions.refresh",
          ["-"] = "actions.parent",
          ["_"] = "actions.open_cwd",
          ["`"] = "actions.cd",
          ["~"] = { "actions.cd", opts = { scope = "tab" } },
          ["gs"] = "actions.change_sort",
          ["gx"] = "actions.open_external",
          ["g."] = "actions.toggle_hidden",
          ["g\\"] = "actions.toggle_trash",
        },
      })
    end,
  }

Expected Behavior

H opens a horizontal split in Oil buffer ### Directory structure _No response_ ### Repro ```Lua -- save as repro.lua -- run with nvim -u repro.lua -- DO NOT change the paths local root = vim.fn.fnamemodify("./.repro", ":p") -- set stdpaths to use .repro for _, name in ipairs({ "config", "data", "state", "runtime", "cache" }) do vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name end -- bootstrap lazy local lazypath = root .. "/plugins/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ "git", "clone", "--filter=blob:none", "--single-branch", "https://github.com/folke/lazy.nvim.git", lazypath, }) end vim.opt.runtimepath:prepend(lazypath) -- install plugins local plugins = { "folke/tokyonight.nvim", { "stevearc/oil.nvim", opts = {}, dependencies = { "nvim-tree/nvim-web-devicons" }, config = function() require("oil").setup({ default_file_explorer = true, delete_to_trash = true, skip_confirm_for_simple_edits = true, view_options = { show_hidden = true, natural_order = true, is_always_hidden = function(name, _) return name == ".." or name == ".git" end, }, win_options = { wrap = true, }, use_default_keymaps = false, keymaps = { ["H"] = { "actions.select", opts = { horizontal = true } }, [""] = false, ["q"] = "actions.close", ["g?"] = "actions.show_help", [""] = "actions.select", [""] = { "actions.select", opts = { vertical = true } }, [""] = false, [""] = { "actions.select", opts = { tab = true } }, [""] = "actions.preview", [""] = "actions.refresh", ["-"] = "actions.parent", ["_"] = "actions.open_cwd", ["`"] = "actions.cd", ["~"] = { "actions.cd", opts = { scope = "tab" } }, ["gs"] = "actions.change_sort", ["gx"] = "actions.open_external", ["g."] = "actions.toggle_hidden", ["g\\"] = "actions.toggle_trash", }, }) end, }, -- add any other plugins here } require("lazy").setup(plugins, { root = root .. "/plugins", }) vim.cmd.colorscheme("tokyonight") -- add anything else here ``` ### Did you check the bug with a clean config? - [X] I have confirmed that the bug reproduces with `nvim -u repro.lua` using the repro.lua file above.
ro0gr commented 3 weeks ago

Unsure whether it's just a typo in your reproduction steps, but you seem to map the <leader>H and try to use the H which are two different things.

Upd. Oh.. sorry. It looks like GH removes the <leader> when it's not marked as a code block..

stevearc commented 3 weeks ago

Works for me. You have bound <leader> plus capital H, so make sure you're using shift. If you want just <leader> plus the h key you should use <leader>h.

The missing description is because once you parameterize the action with opts the stock description is no longer accurate. You'll need to pass one in yourself if you want it to display.

exosyphon commented 2 weeks ago

Thank you for your response! I added "desc" when I map H and I do see that show up which is good.

However, I still am not able to get any keymaps to work with either splitting vertically or horizontally.

Is there something I could try or use to debug what is preventing the actions.select from getting hit?

I am able to use "q" to close Oil so I know that my remaps are working somewhat.

Is there any reason why setting [""] = false or [""] = false and then setting a different keymap would break things?

stevearc commented 2 weeks ago

If you have use_default_keymaps = false, you shouldn't need to set any keymaps to false to disable them. None of them will be created in the first place.

I am not seeing any issues with the repro.lua you posted above. If I do

  1. nvim -u repro.lua .
  2. \H I see a horizontal split, and if I then
  3. <C-s> It makes a vertical split

You are not seeing that happen with these repro steps?

exosyphon commented 2 weeks ago

I was testing in my normal config instead of the repro.lua file. The repro file works as expected now for me. I added the use_default_keymaps = false bit and that got me working. I don't know how that didn't make it into my config.

Thank you for your help!