christoomey / vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
MIT License
5.07k stars 319 forks source link

Nvim cannot change window to Tmux, output of :TmuxNavigatorProcessList is not as displayed #365

Open ctagard opened 9 months ago

ctagard commented 9 months ago

Here is the output of :TmuxNavigatorProcessList:

Ss -zsh S+ nvim

I am running on MacOS 13.5.2, Nvim v0.9.2, Tmux 3.3a. I checked that there were no conflicting keymaps, but when I change to my neovim window I cannot navigate to back to my terminal window.

christoomey commented 9 months ago

Just confirming, can you share the output of :verbose nmap <C-j> in vim, and tmux list-keys | grep C-j in your terminal?

AAlcainaFlexidao commented 9 months ago

I have the same problem, I can't navigate from nvim (version NVIM v0.10.0-dev) to a tmux terminal.

verbose nmap <C-j> image

tmux list-keys | grep C-j image

from a Tmux terminal to nvim works appropriately.

In my case, I'm on Windows 11 + WSL

PierrickGT commented 9 months ago

I am currently facing the same issue. Looks like an update broke it. MacOS 13.4.1, NVIM v0.9.2, tmux 3.3a

ctagard commented 9 months ago

Just confirming, can you share the output of :verbose nmap <C-j> in vim, and tmux list-keys | grep C-j in your terminal?

n * j Go to lower window Last set from Lua

And

bind-key -T copy-mode-vi C-j select-pane -D bind-key -T root C-j if-shell "ps-o state= -o comm=-t '#{pane_tty}' ... looks like the command from the install.

PierrickGT commented 9 months ago

Seems related to this issue: https://github.com/LazyVim/LazyVim/issues/1502

I've fixed it by setting up the following keymap in keymaps.lua:

local map = vim.keymap.set

-- vim-tmux-navigator
if os.getenv("TMUX") then
  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>")
end
HakonHarnes commented 9 months ago

You can also add event: "BufReadPre" to resolve the issue:

return {
  "christoomey/vim-tmux-navigator",
  event = "BufReadPre",
}
ragnarok22 commented 7 months ago
event = "BufReadPre",

I recently migrated from Packer to Lazy and that trigger event fixed the problem for me. Thank you!

avargas05 commented 7 months ago
return {
  "christoomey/vim-tmux-navigator",
  event = "BufReadPre",
}

This solution only worked for me when opening up nvim first then selecting a file. Wouldn't work if opening a file with nvim directly. Adding the keymaps instead worked in both cases.

jaikb commented 3 months ago

You can also add event: "BufReadPre" to resolve the issue:

return {
  "christoomey/vim-tmux-navigator",
  event = "BufReadPre",
}

Sorry I'm a little new to all of this, where would I be adding this? I currently have a .config/nvim/lua/custom/plugins.lua that looks like this:

local plugins = {
  {
    "christoomey/vim-tmux-navigator",
    event = "BufReadPre",
    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

And in my chadrc.lua I have M.plugins = "custom.lua" but this doesn't seem to fix my issue of not being able to navigate from Neovim to the tmux panel. Let me know what I'm doing wrong, thank you

PierrickGT commented 3 months ago

@jaikb in plugins.lua, you should have { "christoomey/vim-tmux-navigator", event = "BufReadPre" },

And the keys should be written in another file like keymaps.lua with this kind of config:

local map = vim.keymap.set

if os.getenv("TMUX") then
  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>")
end
jaikb commented 3 months ago

@jaikb in plugins.lua, you should have { "christoomey/vim-tmux-navigator", event = "BufReadPre" },

And the keys should be written in another file like keymaps.lua with this kind of config:

local map = vim.keymap.set

if os.getenv("TMUX") then
  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>")
end

Thank you for the response @PierrickGT. I went ahead and changed my line in my plugins.lua to just { "christoomey/vim-tmux-navigator", event = "BufReadPre" } and then made a new file called keymaps.lua with the code you provided. That didn't fix my issue though. Do I have to create a new mapping then pass that in my chadrc.lua for it to work? I tried something like that earlier too and that didn't seem to work either.

avargas05 commented 3 months ago

@jaikb Here's what worked for me:

in ~/.config/nvim/lua/plugins/tmux.lua

return {
      "christoomey/vim-tmux-navigator",
}

Adding event = "BufReadPre" on my setup would break it again, so I keep it off.

in ~/.config/nvim/lua/config/keymaps.lua

-- Keymaps are automatically loaded on the VeryLazy event
-- Default keymaps that are always set: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/config/keymaps.lua
-- Add any additional keymaps here

local map = vim.keymap.set

-- vim-tmux-navigator
if os.getenv("TMUX") then
  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>")
end

return {}

If these lines aren't working for you then it's either because you have it in ~/.config/nvim/lua/custom rather than ~/.config/nvim/lua/plugins or ~/.config/nvim/lua/config. I'm not sure what you're trying to do with it in chadrc.lua but it shouldn't need it there in order to work.