Open alex-belost opened 6 months ago
A couple of questions just to confirm:
Presuming neither of those resolve it, can you test out the following:
ps -o state= -o comm= -t $(tmux display -p -t 0 '#{pane_tty}')
I'm seeing the following output, for context.
Ss zsh
S+ vim
it's not working with me too. am using nvchad
-- No longer needed, using tmux navigation integration
-- navigate = {
-- { mode = "n", keymap = "<C-l>", action = "<C-w>l", desc = "pane left" },
-- { mode = "n", keymap = "<C-h>", action = "<C-w>h", desc = "pane right" },
-- { mode = "n", keymap = "<C-j>", action = "<C-w>j", desc = "pane up" },
-- { mode = "n", keymap = "<C-k>", action = "<C-w>k", desc = "pane down" },
-- },
hey @alex-belost
I had my keymaps to navigate between neovim panes, I think this made a conflict with vim-tmux-navigator if you have a similar keymaps, try removing them and check if it solves your problem
I want to mention the the above mappings didn't cause me any trouble at a certain point, this happened recently
I am using:
it's not working with me too. am using nvchad
I am also using Nvchad and it doesnt work, the command works fine but the keybinds don't.
I'm having some similar struggles. Navigation between Vim panes works fine, as does navigation between non-Vim tmux panes; non-Vim to vim does work but Vim to non-Vim does not. I am still able to navigate out of a Vim pane into a tmux pane using <prefix>-<arrows>
.
Additionally, I don't get any output from :TmuxNavigatorProcessList
, but running ps -o state= -o comm= -t $(tmux display -p -t 0 '#{pane_tty}')
with a Vim instance in pane 0 gives:
S zsh
S nvim
I'm using
On a NixOS 24.11 system and using home-manager 24.11 to manage my Neovim and tmux configs:
neovim = {
enable = true;
vimAlias = true;
defaultEditor = true;
coc.enable = true;
plugins = with pkgs.vimPlugins; [
coc-nvim
coc-rust-analyzer
# coc-nix
coc-json
coc-go
coc-sh
plenary-nvim
indentLine
# vim-system-copy
vim-tmux-navigator
# vim-rainbow
lualine-nvim
nvim-web-devicons
vim-commentary
vim-oscyank
vimtex
telescope-nvim
vim-multiple-cursors
gruvbox-material
];
extraConfig = ''
set mouse=
set guicursor=n-v-c-i:block
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set autoindent
syntax on
set number relativenumber
set shell=/usr/bin/zsh
set laststatus=2
set nohlsearch
set showcmd
set splitbelow
set splitright
" map <Left> <Nop>
" map <Right> <Nop>
" map <Up> <Nop>
" map <Down> <Nop>
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 4
let g:netrw_altv = 1
let g:netrw_winsize = 25
noremap <silent> <C-t> :10split <bar> :term <CR>
tnoremap <Esc> <C-\><C-n>
"allow coc completion on tab
inoremap <silent><expr> <TAB> coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<TAB>"
let g:rainbow_active = 1
let g:system_copy_enable_osc52 = 1
" let g:oscyank_term = 'tmux'
colorscheme gruvbox-material
set listchars=tab:➤\ ,trail:◆ et listchars=tab:➤\ ,trail:◆
let filetypes = ['json']
if index(filetypes, &filetype) != -1
set conceallevel=0
endif
nnoremap <C-p> <cmd>lua require('telescope.builtin').git_files()<cr>
nnoremap <C-g> <cmd>lua require('telescope.builtin').live_grep()<cr>
nnoremap <C-b> <cmd>lua require('telescope.builtin').buffers()<cr>
nnoremap <C-i> <cmd>lua require('telescope.builtin').find_files()<cr>
" VimTex
" Filter out some compilation warning messages from QuickFix display
let g:vimtex_quickfix_ignore_filters = [
\ 'Underfull \\hbox',
\ 'Overfull \\hbox',
\ 'LaTeX Warning: .\+ float specifier changed to',
\ 'LaTeX hooks Warning',
\ 'Package siunitx Warning: Detected the "physics" package:',
\ 'Package hyperref Warning: Token not allowed in a PDF string',
\]
let g:vimtex_view_method = 'zathura'
let g:tmux_navigator_disable_when_zoomed = 1
'';
extraLuaConfig = ''
local config = {
options = {
icons_enabled = true,
theme = 'gruvbox-material',
component_separators = "",
section_separators = "",
disabled_filetypes = {
statusline = {},
winbar = {},
},
ignore_focus = {},
always_divide_middle = true,
globalstatus = false,
refresh = {
statusline = 1000,
tabline = 1000,
winbar = 1000,
}
},
sections = {
lualine_a = {'mode'},
lualine_b = {'branch', 'diff', 'diagnostics'},
lualine_c = {'buffers'},
lualine_x = {'searchcount'},
lualine_y = {'progress'},
lualine_z = {'location'}
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_c = {'filename'},
lualine_x = {'location'},
lualine_y = {},
lualine_z = {}
},
tabline = {},
winbar = {},
inactive_winbar = {},
extensions = {}
}
require('lualine').setup(config)
require('telescope').setup{
defaults = {
mappings = {
i = {
["<CR>"] = "select_default",
}
}
}
}
'';
};
tmux = {
enable = true;
plugins = with pkgs.tmuxPlugins; [
sensible
vim-tmux-navigator
yank
# tmux-power-zoom
gruvbox
];
extraConfig = ''
unbind C-b
set -g prefix C-Space
bind C-Space send-prefix
bind | split-window -h -c "#{pane_current_path}"
bind _ split-window -v -c "#{pane_current_path}"
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
'';
};
@ahmedsayedabdelsalam , @supinie
I've been tinkering with nvchad and ran into a similar issue. Doing the following worked:
--- for nvchad users, this is in the ~/.config/nvim/lua/mappings.lua file
local unmap = vim.keymap.del
--- This fixes an issue with the vim-tmux-navigator + nvchad in which the base nvchad
--- mapping were conflicting with vim-tmux-navigator ones.
unmap("n", "<c-h>")
unmap("n", "<c-j>")
unmap("n", "<c-k>")
unmap("n", "<c-l>")
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>")
So, for me, it simply appears it was a conflicting mapping issue.
N.B. My tmux-navigator plugin is set as lazy = false
. Might this cause it to be loaded before the nvchad mapping, causing the override?
@TheCoconutChef, I just tried your method, unfortunately I don't think the root cause is the same as I get an error trying to unmap a mapping that does not exist. I did try re-doing the maps without the unmapping and with tmux_navigator_no_mappings
set but the issue persists unfortunately.
@ahmedsayedabdelsalam , @supinie
I've been tinkering with nvchad and ran into a similar issue. Doing the following worked:
--- for nvchad users, this is in the ~/.config/nvim/lua/mappings.lua file local unmap = vim.keymap.del --- This fixes an issue with the vim-tmux-navigator + nvchad in which the base nvchad --- mapping were conflicting with vim-tmux-navigator ones. unmap("n", "<c-h>") unmap("n", "<c-j>") unmap("n", "<c-k>") unmap("n", "<c-l>") 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>")
So, for me, it simply appears it was a conflicting mapping issue.
N.B. My tmux-navigator plugin is set as
lazy = false
. Might this cause it to be loaded before the nvchad mapping, causing the override?
This worked for me. Thanks a lot!
The reason it was breaking for me was that Ctrl + {h,j,k,l} is already mapped in lazyvim.
I have no idea if this is a good idea or not (EDIT I figured out a better way to do this below so check that out before you do this one), but this is what I ended up getting to work in LazyVim. It just deletes the old keymaps when they first load I believe:
{
"christoomey/vim-tmux-navigator",
keys = {
{
"<c-h>",
function ()
vim.keymap.del("n", "<c-h>");
return "<cmd><C-U>TmuxNavigateLeft<cr>"
end,
desc="Tmux Navigate Left"
},
{
"<c-j>",
function ()
vim.keymap.del("n", "<c-j>");
return "<cmd><C-U>TmuxNavigateDown<cr>"
end,
desc="Tmux Navigate Down"
},
{
"<c-k>",
function ()
vim.keymap.del("n", "<c-k>");
return "<cmd><C-U>TmuxNavigateUp<cr>"
end,
desc="Tmux Navigate Up"
},
{
"<c-l>",
function ()
vim.keymap.del("n", "<c-l>");
return "<cmd><C-U>TmuxNavigateRight<cr>"
end,
desc="Tmux Navigate Right"
},
},
},
Ooops that last one was a little odd. I think I just need to provide the remap option to neovim instead of deleting the keymap which is much cleaner and probably the normal way people would do it in lazyvim:
{
"christoomey/vim-tmux-navigator",
remap = true,
keys = {
{
"<c-h>",
"<cmd><C-U>TmuxNavigateLeft<cr>",
desc="Tmux Navigate Left"
},
{
"<c-j>",
"<cmd><C-U>TmuxNavigateDown<cr>",
desc="Tmux Navigate Down"
},
{
"<c-k>",
"<cmd><C-U>TmuxNavigateUp<cr>",
desc="Tmux Navigate Up"
},
{
"<c-l>",
"<cmd><C-U>TmuxNavigateRight<cr>",
desc="Tmux Navigate Right"
},
},
},
Final Edit actually it appears remap isn't even an available option so I don't know why it wasn't working before, but this is my minimal config. Maybe I had an uninstalled dependency.
{
"christoomey/vim-tmux-navigator",
keys = {
{
"<c-h>",
"<cmd><C-U>TmuxNavigateLeft<cr>",
desc="Tmux Navigate Left"
},
{
"<c-j>",
"<cmd><C-U>TmuxNavigateDown<cr>",
desc="Tmux Navigate Down"
},
{
"<c-k>",
"<cmd><C-U>TmuxNavigateUp<cr>",
desc="Tmux Navigate Up"
},
{
"<c-l>",
"<cmd><C-U>TmuxNavigateRight<cr>",
desc="Tmux Navigate Right"
},
},
},
I had this configuration on a Mac book iterm2 and it works, but on windows using wsl2, ran into the same error. I am currently using a different plugin shown below and it works:
{
"alexghergh/nvim-tmux-navigation",
event = "VeryLazy",
config = function()
local nvim_tmux_nav = require("nvim-tmux-navigation")
nvim_tmux_nav.setup({
disable_when_zoomed = true,
-- defaults to false
keybindings = {
left = "<C-h>",
down = "<C-j>",
up = "<C-k>",
right = "<C-l>",
last_active = "<C-\\>",
next = "<C-Space>",
},
})
end,
},
Output from
:TmuxNavigatorProcessList
Nvim build:
LazyVim
Tmux config:
Output from
ps
:command:
tty
:/dev/ttys005
command:tmux display '#{pane_tty}'
->/dev/ttys004