Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ctagard opened this issue Sep 26, 2023 · 12 comments

Comments

@ctagard
Copy link

ctagard commented Sep 26, 2023

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
Copy link
Owner

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
Copy link

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
Copy link

PierrickGT commented Sep 27, 2023

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
Copy link
Author

ctagard commented Sep 29, 2023

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
Copy link

Seems related to this issue: LazyVim/LazyVim#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
Copy link

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

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

@ragnarok22
Copy link

event = "BufReadPre",

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

@avargas05
Copy link

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
Copy link

jaikb commented Mar 8, 2024

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
Copy link

PierrickGT commented Mar 8, 2024

@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
Copy link

jaikb commented Mar 8, 2024

@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
Copy link

avargas05 commented Mar 9, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants