tmux.nvim icon indicating copy to clipboard operation
tmux.nvim copied to clipboard

Use default key bindings

Open yamatsum opened this issue 3 years ago • 7 comments

I want to use vim's default keybindings (Ctrl-w + hjkl) to move between vim and tmux So I set it as follows:

init.lua (NVIM v0.6.0-dev+bec7f47ce)

local map = vim.api.nvim_set_keymap
local map_opts = {noremap = true, silent = true}

map("", "<C-w>h", ":lua require'tmux'.move_left()<cr>", map_opts)
map("", "<C-w>j", ":lua require'tmux'.move_bottom()<cr>", map_opts)
map("", "<C-w>k", ":lua require'tmux'.move_top()<cr>", map_opts)
map("", "<C-w>l", ":lua require'tmux'.move_right()<cr>", map_opts)

tmux.conf (tmux 3.2a)

bind -n C-w switch-client -T NAVIGATOR

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

bind -T NAVIGATOR h if-shell "$is_vim" "send-keys C-w h"  "select-pane -L"
bind -T NAVIGATOR j if-shell "$is_vim" "send-keys C-w j"  "select-pane -D"
bind -T NAVIGATOR k if-shell "$is_vim" "send-keys C-w k"  "select-pane -U"
bind -T NAVIGATOR l if-shell "$is_vim" "send-keys C-w l"  "select-pane -R"

bind -T NAVIGATOR C-w send-keys C-w

It was possible, but it stopped responding from a certain version What's wrong? Could the plugin support the default key bindings as well?

yamatsum avatar Oct 29 '21 08:10 yamatsum

As per the README, using enable_default_keybindings didn't work either. I can move between tmux panels, but I can't move between vim windows in vim on tmux

yamatsum avatar Oct 30 '21 03:10 yamatsum

Heho,

had a break from tmux and stuff (concentrating on work). Is it still not possible? I guess it was the nvim version because i cannot reproduce the behavior with default keybindings.

Kind regards

aserowy avatar Dec 13 '21 07:12 aserowy

@aserowy Thank you for your reply Try it with the above settings! Still doesn't work The version is stable v0.6.0

yamatsum avatar Dec 13 '21 09:12 yamatsum

Heho,

you wrote, that even the defaults are not working. Is this still the case for you?

Kind regards

aserowy avatar Dec 16 '21 17:12 aserowy

Default binding works for my case.

local keymaps = require("tmux.keymaps")
keymaps.register("n", {
    ["<C-w>h"] = [[<cmd>lua require('tmux').move_left()<cr>]],
    ["<C-w>j"] = [[<cmd>lua require('tmux').move_bottom()<cr>]],
    ["<C-w>k"] = [[<cmd>lua require('tmux').move_top()<cr>]],
    ["<C-w>l"] = [[<cmd>lua require('tmux').move_right()<cr>]],
})

ErickChacon avatar Mar 27 '22 15:03 ErickChacon

@aserowy @ErickChacon When I move from vim on tmux to pane on tmux, I feel that :lua require('tmux').move_*() doesn't work. From tmux pane to tmux pane works fine. Moving from vim on tmux to vim on tmux also works fine.

yamatsum avatar Apr 20 '22 15:04 yamatsum

https://github.com/numToStr/Navigator.nvim works fine

yamatsum avatar Apr 21 '22 01:04 yamatsum