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 to tmux does not work #355

Closed
aziz76 opened this issue Jun 10, 2023 · 16 comments
Closed

nvim to tmux does not work #355

aziz76 opened this issue Jun 10, 2023 · 16 comments

Comments

@aziz76
Copy link

aziz76 commented Jun 10, 2023

It seems TmuxNavigator can't find the tmux process because :TmuxNavigatorProcessList shows:

Ss   -zsh
S+   nvim 

Switching works from tmux to nvim and within nvim but not nvim to tmux. Not sure if I am doing something wrong.

Would appreciate any help.

@christoomey
Copy link
Owner

Just to confirm, do you have the vim plugin installed? (https://github.com/christoomey/vim-tmux-navigator#vim)

Likewise, can you check the Vim key mappings per https://github.com/christoomey/vim-tmux-navigator#vim---tmux-doesnt-work?

@aziz76
Copy link
Author

aziz76 commented Jun 11, 2023

Yes I have the vim-tmux-navigator plugin installed and the mappings have been set too. Here are my plugins.lua and mappings.lua (I'm running nvchad):

plugins.lua:

local plugins = {
  {
    "christoomey/vim-tmux-navigator",
    lazy = false,
  },
  {
    "vim-crystal/vim-crystal",
    ft = "crystal"
  },
  {
    "neovim/nvim-lspconfig",
    config = function()
      require "plugins.configs.lspconfig"
      require "custom.configs.lspconfig"
    end,
  },
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "rust-analyzer",
      },
    },
  }
}
return plugins

mappings.lua

local M = {}

M.general = {
  n = {
    ["<C-h>"] = { "<cmd> TmuxNavigationLeft<CR>", "window left" },
    ["<C-l>"] = { "<cmd> TmuxNavigationRight<CR>", "window right" },
    ["<C-j>"] = { "<cmd> TmuxNavigationDown<CR>", "window down" },
    ["<C-k>"] = { "<cmd> TmuxNavigationUp<CR>", "window up" },
  }
}

@christoomey
Copy link
Owner

Just to confirm as the mappings can be overriden by later config lines, can you check them as per https://github.com/christoomey/vim-tmux-navigator#vim---tmux-doesnt-work?

@aziz76
Copy link
Author

aziz76 commented Jun 11, 2023 via email

@nickwbarber
Copy link

TmuxNavigationLeft

This is almost the correct command. It should be TmuxNavigateLeft, etc.

@aziz76
Copy link
Author

aziz76 commented Jun 18, 2023

Good spot thanks. Unfortunately it didn't fix the issue.

@quinnda-hub
Copy link

I'm having the same issue. Also running nvchad and my plugin.lua and mappings.lua look the same as what aziz76 has. Also have the exact same behaviour as described by him above. I'm on Fedora 38.

@christoomey
Copy link
Owner

Yes I checked and I don’t think that is the case. In fact the key mappings are working within neovim. For example when nvim-tree is open I am able to switch between the editor and the nvim-tree using C-h, C-L. It’s only switching out of nvim that isn’t working.

@aziz76 just to double check here, can you share the output of :verbose nmap <C-h>? It's possible you have a mapping like nmap <C-h> <C-w>h which would let navigation in Vim work, but would not allow for the vim<>tmux integration.

@aziz76
Copy link
Author

aziz76 commented Jul 4, 2023 via email

@christoomey
Copy link
Owner

Yup, looks like you've got a conflicting mapping somewhere else in your config -- you'll need to find those conflicting config lines and remove them to get things working. Going to close this issue now as it looks like the issue is in your config rather than the plugin.

@Debajyati
Copy link

Debajyati commented Jul 6, 2023

@aziz76 Hey hello, just to know if you've fixed the issue in your config file. Because I was having the same issue from yesterday(I started setting up nvim with 'NV Chad' 1.5 days ago) , & I solved the problem in my config file few moments ago. Now I can seamlessly move from nvim to tmux and vice versa with shortcuts (<Ctrl+h>, <Ctrl+j>, <Ctrl+k> and <Ctrl+l>). Will be glad if I be able to help.

@jingkeke
Copy link

ref NvChad/NvChad#1984

M.disabled = {
  n = {
    -- Disable to allow the plugin nvim-tmux-navigator to bind (see custom/plugins.lua)
    ["<C-h>"] = "",
    ["<C-l>"] = "",
    ["<C-j>"] = "",
    ["<C-k>"] = "",
  }
}

@aziz76
Copy link
Author

aziz76 commented Jul 12, 2023

Not sure I understand, do I put these lines in custom/mappings.lua or custom/plugins.lua? I couldn't find any conflicting bindings as I have not assigned them anywhere else?

@Debajyati
Copy link

@aziz76 I see you didn't return M at the last line in your mappings.lua file. and you can see the lines in my tmux.conf file below. If you find anything missing in your file you can add it there and see if starts to work. After adding those lines of Vim style pane selection and Shift Alt Vim keys to swich windows section, I can easily switch from nvim to tmux and vice versa using Ctrl+h or j or k or l based on direction.

set-option -sa terminal-overrides ",xterm*:Tc"
set -g mouse on

# Vim style pane selection
bind h select-pane -L
bind j select-pane -D 
bind k select-pane -U
bind l select-pane -R

# Use Alt-arrow keys without prefix key to switch panes
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D

# Shift Alt vim keys to switch windows
bind -n M-H previous-window
bind -n M-L next-window

set -sg escape-time 1
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'```

@Debajyati
Copy link

Also make sure you have the line M.mappings = require "custom.mappings" in your chadrc.lua file.

local M = {}

M.general = {
  n = {
    ["<C-h>"] = { "<cmd> TmuxNavigateLeft<CR>", "window left" },
    ["<C-l>"] = { "<cmd> TmuxNavigateRight<CR>", "window right" },
    ["<C-j>"] = { "<cmd> TmuxNavigateDown<CR>", "window down" },
    ["<C-k>"] = { "<cmd> TmuxNavigateUp<CR>", "window up" },
  }
}

return M

And keep your mappings.lua file same as above. After all of these configurations, your navigation from nvim to tmux and tmux to nvim should work.

@helderberto
Copy link

I fixed it defining the custom keymappings as you can see here.

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

7 participants