mrjones2014 / smart-splits.nvim

🧠 Smart, seamless, directional navigation and resizing of Neovim + terminal multiplexer splits. Supports tmux, Wezterm, and Kitty. Think about splits in terms of "up/down/left/right".
MIT License
831 stars 33 forks source link

feat(mux): Use tmux inside kitty and compatible with window shortcuts #208

Closed mochouaaaaa closed 2 months ago

mochouaaaaa commented 2 months ago

kitty.conf The shortcut here is passed to tmux

map cmd+j kitten neighboring_window.py bottom cmd+j
map cmd+k kitten neighboring_window.py top    cmd+k
map cmd+h kitten neighboring_window.py left   cmd+h
map cmd+l kitten neighboring_window.py right  cmd+l

map --when-focus-on var:IS_NVIM cmd+j
map --when-focus-on var:IS_NVIM cmd+k
map --when-focus-on var:IS_NVIM cmd+h
map --when-focus-on var:IS_NVIM cmd+l

map ctrl+shift+j kitten relative_resize.py down  3 ctrl+shift+j 
map ctrl+shift+k kitten relative_resize.py up    3 ctrl+shift+k
map ctrl+shift+h kitten relative_resize.py left  3 ctrl+shift+h
map ctrl+shift+l kitten relative_resize.py right 3 ctrl+shift+l

map --when-focus-on var:IS_NVIM ctrl+shift+j
map --when-focus-on var:IS_NVIM ctrl+shift+k
map --when-focus-on var:IS_NVIM ctrl+shift+h
map --when-focus-on var:IS_NVIM ctrl+shift+l

map cmd+ctrl+j kitten split_window.py down    cmd+ctrl+j
map cmd+ctrl+k kitten split_window.py up      cmd+ctrl+k
map cmd+ctrl+h kitten split_window.py left    cmd+ctrl+h
map cmd+ctrl+l kitten split_window.py right   cmd+ctrl+l

tmux.conf

bind-key -n M-h if -F "#{@pane-is-vim}" 'send-keys M-h'  'select-pane -L'
bind-key -n M-j if -F "#{@pane-is-vim}" 'send-keys M-j'  'select-pane -D'
bind-key -n M-k if -F "#{@pane-is-vim}" 'send-keys M-k'  'select-pane -U'
bind-key -n M-l if -F "#{@pane-is-vim}" 'send-keys M-l'  'select-pane -R'

bind-key -n C-S-h if -F "#{@pane-is-vim}" 'send-keys C-S-h' 'resize-pane -L 3'
bind-key -n C-S-j if -F "#{@pane-is-vim}" 'send-keys C-S-j' 'resize-pane -D 3'
bind-key -n C-S-k if -F "#{@pane-is-vim}" 'send-keys C-S-k' 'resize-pane -U 3'
bind-key -n C-S-l if -F "#{@pane-is-vim}" 'send-keys C-S-l' 'resize-pane -R 3'

bind-key -n C-M-k if -F "#{@pane-is-vim}" 'send-keys C-M-k' 'split-window -v -c "#{pane_current_path}"'
bind-key -n C-M-j if -F "#{@pane-is-vim}" 'send-keys C-M-j' 'split-window -v -c "#{pane_current_path}"'
bind-key -n C-M-l if -F "#{@pane-is-vim}" 'send-keys C-M-l' 'split-window -h -c "#{pane_current_path}"'
bind-key -n C-M-h if -F "#{@pane-is-vim}" 'send-keys C-M-h' 'split-window -h -c "#{pane_current_path}"'

neovim On mac systems, the cmd key cannot be used with ‘D’ but rather ‘M’, because tmux sends over the M

vim.keymap.set("n", "<C-S-k>", function()
    smart_splits.resize_up()
end)
vim.keymap.set("n", "<C-S-j>", function()
    smart_splits.resize_down()
end)
vim.keymap.set("n", "<C-S-h>", function()
    smart_splits.resize_left()
end)
vim.keymap.set("n", "<C-S-l>", function()
    smart_splits.resize_right()
end)

vim.keymap.set("n",  "<M-k>", function()
    smart_splits.move_cursor_up()
end)
vim.keymap.set("n", "<M-j>", function()
    smart_splits.move_cursor_down()
end)
vim.keymap.set("n", "<M-h>", function()
    smart_splits.move_cursor_left()
end)
vim.keymap.set("n","<M-l>", function()
    smart_splits.move_cursor_right()
end)

local mux = require("smart-splits.mux").get()
vim.keymap.set("n","<M-C-k>", function()
    mux.split_pane("up")
end)
vim.keymap.set("n", "<M-C-j>", function()
    mux.split_pane("down")
end)
vim.keymap.set("n", "<M-C-h>", function()
    mux.split_pane("left")
end)
vim.keymap.set("n", "<M-C-l>", function()
    mux.split_pane("right")
end)

kitty_tmux_move kitty_tmux_resize

mrjones2014 commented 2 months ago

Can you explain a little more about what these changes are doing, why they're needed, and whether they'll interfere with people just using Kitty's mux and not using tmux?

mochouaaaaa commented 2 months ago

It does not interfere with any way of use There is no effect when using only kitty, as no code has been changed. In the use of tmux and kiity just one more operation, that is, the shortcut key send to tmux, when using tmux, at this time the shortcut key operation will call tmux's window operation instead of kitty's.