christoomey/vim-tmux-navigator

Can't get this to work from NeoVim to Tmux

jaikb opened this issue · 3 comments

Followed all the instructions in the README.md and the way I did it was make a plugins.lua file in .config/nvim/lua/custom folder where I have this:

local plugins = {
  {
    "christoomey/vim-tmux-navigator",
    cmd = {
      "TmuxNavigateLeft",
      "TmuxNavigateDown",
      "TmuxNavigateUp",
      "TmuxNavigateRight",
      "TmuxNavigatePrevious",
    },
    keys = {
      { "<c-h>", "<cmd><C-U>TmuxNavigateLeft<cr>" },
      { "<c-j>", "<cmd><C-U>TmuxNavigateDown<cr>" },
      { "<c-k>", "<cmd><C-U>TmuxNavigateUp<cr>" },
      { "<c-l>", "<cmd><C-U>TmuxNavigateRight<cr>" },
      { "<c-\\>", "<cmd><C-U>TmuxNavigatePrevious<cr>" },
    },
  }
}

return plugins

Then in my chadrc.lua file I have M.plugins = 'custom.plugins' and it installs the plugin using Lazy, but the keybinds won't let me go from NeoVim to the TMUX pane. Any help?

I had same issue. I fixed it with setting lazy to false and changing "config" to "init". That's my current config:

return {
    "christoomey/vim-tmux-navigator",
    lazy = false,
    cmd = {
        "TmuxNavigateLeft",
        "TmuxNavigateDown",
        "TmuxNavigateUp",
        "TmuxNavigateRight",
        "TmuxNavigatePrevious",
    },
    init = function()
        -- local nav = require("nvim-tmux-navigator")
        local map = vim.keymap.set
        map("n", "<c-h>", "<cmd>TmuxNavigateLeft<cr>")
        map("n", "<c-j>", "<cmd>TmuxNavigateDown<cr>")
        map("n", "<c-k>", "<cmd>TmuxNavigateUp<cr>")
        map("n", "<c-l>", "<cmd>TmuxNavigateRight<cr>")
        map("n", "<c-\\>", "<cmd>TmuxNavigatePrevious<cr>")
    end,
}

Hi @jaikb,
I am using NvChad as well. If you run :Telescope keymaps and search c-h, you will find the command was successfully bound to "ov" modes. I guess the configuration was good, but other key settings from plugins/code in NvChad were set after lazy. I removed line 21 to 24 from core/mappings.lua and everything works perfectly now.
Note: Ideally we shouldn't change any files not in custom folder, but I don't know how to avoid overwriting keymaps.
image

HTH.

Hey @alex-fu-cn thanks for the detailed notes there. I believe you found the source of the issue (conflicting key bindings coming from other NvChad config/plugins). I’m going to close this now with that context.