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

Default keybindings work within tmux panes but not nvim panes using Lazy #92

Closed
vicrdguez opened this issue Feb 6, 2023 · 6 comments
Closed
Labels
question Further information is requested

Comments

@vicrdguez
Copy link

Hi!

I recently installed the plugin, however looks like there is no way I can make <C-hjlk> work.

I'm using the default configuration as mentioned in the readme, navigation within tmux panes works good but never across neovim splits.

Neovim config

  use({
      "aserowy/tmux.nvim",
      config = function() return require("tmux").setup({
          sync_clipboard = false,
          sync_unnamed = false,
      }) end
  })

tmux config

is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(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'

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

Curiously enough executing :lua require('tmux').move_right() (or any of the other variants) works well. I've tried to set up the keymaps manually with no success. I also tried binding the actions to a different set of bindings:

vim.keymap.set({'n', 't'}, '<leader>wj', function () tmux.move_bottom() end)
vim.keymap.set({'n', 't'}, '<leader>wk', function () tmux.move_top() end)
vim.keymap.set({'n', 't'}, '<leader>wl', function() tmux.move_right() end)
vim.keymap.set({'n', 't'}, '<leader>wh', function() tmux.move_left() end)

This works as expected, and is what I'm using now as a fallback while trying to solve this since ideally I prefer tmux bindings and nvim bindings to be the same

I tried to deactivate other plugins just in case they might be overwriting the specific default bindings but I had no luck with that either.

Any Idea on how to troubleshoot this one?
Thanks!

@aserowy
Copy link
Owner

aserowy commented Feb 27, 2023

Heho,

can you please try to set

    -- enables default keybindings (C-hjkl) for normal mode
    enable_default_keybindings = true,

explicitly? Maybe we have a bug in the settings resolvement.

Kind regards
Alexander

@aserowy aserowy added the question Further information is requested label Feb 27, 2023
@LeoAdL
Copy link

LeoAdL commented Mar 2, 2023

Are you using Lazy.nvim by any chance?

I had the same problem as here (LazyVim/LazyVim#277), and had to override the default settings, by adding to 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
-- Move to window using the <ctrl> hjkl keys

local Util = require("lazyvim.util")
local function map(mode, lhs, rhs, opts)
  local keys = require("lazy.core.handler").handlers.keys
  ---@cast keys LazyKeysHandler
  -- do not create the keymap if a lazy keys handler exists
  if not keys.active[keys.parse({ lhs, mode = mode }).id] then
    opts = opts or {}
    opts.silent = opts.silent ~= false
    vim.keymap.set(mode, lhs, rhs, opts)
  end
end

map("n", "<C-h>", "<cmd>lua require'tmux'.move_left()<cr>", { desc = "Go to left window" })
map("n", "<C-j>", "<cmd>lua require'tmux'.move_bottom()<cr>", { desc = "Go to lower window" })
map("n", "<C-k>", "<cmd>lua require'tmux'.move_top()<cr>", { desc = "Go to upper window" })
map("n", "<C-l>", "<cmd>lua require'tmux'.move_right()<cr>", { desc = "Go to right window" })

Hopefully that solves your problem!

@lucasrabiec
Copy link

lucasrabiec commented Mar 5, 2023

#92 (comment)
Works for me, TY @LeoAdL

@aserowy
Copy link
Owner

aserowy commented Sep 3, 2023

can we do anything on this side to enable this by default?

@LeoAdL

@sollymay
Copy link

Had the same problem and was driving me insane! Thank you @LeoAdL!!!

@aserowy
Copy link
Owner

aserowy commented Jan 2, 2024

Are you using Lazy.nvim by any chance?

I had the same problem as here (LazyVim/LazyVim#277), and had to override the default settings, by adding to 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
-- Move to window using the <ctrl> hjkl keys

local Util = require("lazyvim.util")
local function map(mode, lhs, rhs, opts)
  local keys = require("lazy.core.handler").handlers.keys
  ---@cast keys LazyKeysHandler
  -- do not create the keymap if a lazy keys handler exists
  if not keys.active[keys.parse({ lhs, mode = mode }).id] then
    opts = opts or {}
    opts.silent = opts.silent ~= false
    vim.keymap.set(mode, lhs, rhs, opts)
  end
end

map("n", "<C-h>", "<cmd>lua require'tmux'.move_left()<cr>", { desc = "Go to left window" })
map("n", "<C-j>", "<cmd>lua require'tmux'.move_bottom()<cr>", { desc = "Go to lower window" })
map("n", "<C-k>", "<cmd>lua require'tmux'.move_top()<cr>", { desc = "Go to upper window" })
map("n", "<C-l>", "<cmd>lua require'tmux'.move_right()<cr>", { desc = "Go to right window" })

Hopefully that solves your problem!

I guess this is the solution. Im pinning and closing the issue.

tyvm for all the investigation!

@aserowy aserowy closed this as completed Jan 2, 2024
@aserowy aserowy pinned this issue Jan 2, 2024
@aserowy aserowy changed the title Default keybindings work within tmux panes but not nvim panes Default keybindings work within tmux panes but not nvim panes using Lazy Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

5 participants