oil.nvim icon indicating copy to clipboard operation
oil.nvim copied to clipboard

bug: can not remap key to open split.

Open meicale opened this issue 1 year ago • 6 comments

Did you check the docs and existing issues?

  • [X] I have read the docs
  • [X] I have searched the existing issues

Neovim version (nvim -v)

0.9.2

Operating system/version

wsl2 ubuntu 22.04

Describe the bug

Thank you for the awesome plugin and I like it a lot! I encounter this problem to remap another key to open my the file selected. In the setup function, I have this

          ["<C-h>"] = false,
          ["<C-e>"] = { "actions.select", opts = { horizontal = true } },
          ["<C-l>"] = false,
          ["<C-r>"] = "actions.refresh",

I can change refresh to ctrl+r but ctrl+e cannot open the file horizontally. I can still use ctrl+s to open file vertically. Thank you for your attention!

What is the severity of this bug?

minor (annoyance)

Steps To Reproduce

update the config oil.nvim config in lazyvim. On oil buffer, Press ctrl+e, and Nothing changed!

Expected Behavior

On oil buffer, Press ctrl+e, and open the file horizotally.

Directory structure

No response

Repro

-- 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",
        config = function()
            require("oil").setup({
              -- add any needed settings here
            })
        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.

meicale avatar Jun 13 '24 08:06 meicale

My guess is you have something else overriding your <C-e> binding. I tried it with this minimal repro file and it works fine

-- 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",
    config = function()
      require("oil").setup({
        keymaps = {
          ["<C-h>"] = false,
          ["<C-e>"] = { "actions.select", opts = { horizontal = true } },
          ["<C-l>"] = false,
          ["<C-r>"] = "actions.refresh",
        },
      })
    end,
  },
  -- add any other plugins here
}
require("lazy").setup(plugins, {
  root = root .. "/plugins",
})

vim.cmd.colorscheme("tokyonight")
-- add anything else here

You can inspect what the keymap for <C-e> is in the oil buffer with :nmap <C-e>.

stevearc avatar Jun 13 '24 19:06 stevearc

I have the same issue. I remapped the open in split keybinds to V and H like so:

      ['V'] = { 'actions.select', opts = { vertical = true }, desc = 'Open the entry in a vertical split' },
      ['H'] = { 'actions.select', opts = { horizontal = true }, desc = 'Open the entry in a horizontal split' },

but when I do :map <C-h> I still get

<C-H>       *@<Lua 375: ~/.local/share/nvim/lazy/oil.nvim/lua/oil/keymap_util.lua:42>                                                                                       Open the entry in a horizontal split

I'm using kickstart and I added my keybindings to after the custom plugins are loaded but I think because it's lazy loaded it doesn't matter, the oil keybinds still cover my keybinds.

Supetorus avatar Aug 23 '24 17:08 Supetorus

I am having the same issue - I can't figure out how to unbind a key. I use <C-h/j/k/l> to jump between nvim windows. Have tried setting those to nil and false (as in this example) for Oil config, but neither seems to do anything.

Also tysm for this plugin, I am truly loving it!

lellingsen avatar Sep 11 '24 18:09 lellingsen

Please provide a minimal repro file like the one I constructed above that demonstrates the issue

stevearc avatar Sep 11 '24 20:09 stevearc

@stevearc Oh gosh, apparently I was totally wrong. Setting it to false totally worked for me! Apologies for that, I honestly am not sure what happened. Thank you very much for all of your hard work and answering my silly question!

lellingsen avatar Sep 13 '24 17:09 lellingsen

I am not sure if this behavior is intended, but it seems that mapping ["<c-n>"] to false has no effect. However, mapping ["<C-n>"] works as expected, suggesting that letter case is significant.

ButterSus avatar Jan 27 '25 07:01 ButterSus