From 30085a1062706b8af96a312b058197feb9650f8a Mon Sep 17 00:00:00 2001 From: Henrik Bakken Date: Sun, 20 Apr 2025 00:16:42 +0200 Subject: [PATCH] nvim+tmux smart-splits --- nvim/init.lua | 36 +++++++++++++++------------- tmux/tmux.conf | 64 +++++++++++++++++++++++++------------------------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/nvim/init.lua b/nvim/init.lua index 0e757a9..b537ac1 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1201,22 +1201,26 @@ local function makespec_todocomments() } end -local function makespec_tmuxnav() +local function makespec_smartsplits() return { - -- tmux / vim interop - "alexghergh/nvim-tmux-navigation", - config = function() - require("nvim-tmux-navigation").setup({ - disable_when_zoomed = true, -- defaults to false - keybindings = { - left = "", - down = "", - up = "", - right = "", - last_active = "", - }, - }) - end, + "mrjones2014/smart-splits.nvim", + lazy = false, + -- stylua: ignore + keys = { + { "", function() require("smart-splits").move_cursor_left() end, { desc = "Go to Left Window", remap = true } }, + { "", function() require("smart-splits").move_cursor_down() end, { desc = "Go to Left Window", remap = true } }, + { "", function() require("smart-splits").move_cursor_up() end, { desc = "Go to Left Window", remap = true } }, + { "", function() require("smart-splits").move_cursor_right() end, { desc = "Go to Left Window", remap = true } }, + { "", function() require("smart-splits").move_cursor_previous() end, { desc = "Go to Previous Window", remap = true } }, + { "", function() require("smart-splits").resize_left() end, { desc = "Resize Window Left", remap = true } }, + { "", function() require("smart-splits").resize_down() end, { desc = "Resize Window Down", remap = true } }, + { "", function() require("smart-splits").resize_up() end, { desc = "Resize Window Up", remap = true } }, + { "", function() require("smart-splits").resize_right() end, { desc = "Resize Window Right", remap = true } }, + { "h", function() require("smart-splits").swap_buf_left() end, { desc = "Swap Buffer Left", remap = true } }, + { "j", function() require("smart-splits").swap_buf_down() end, { desc = "Swap Buffer Down", remap = true } }, + { "k", function() require("smart-splits").swap_buf_up() end, { desc = "Swap Buffer Up", remap = true } }, + { "l", function() require("smart-splits").swap_buf_right() end, { desc = "Swap Buffer Right", remap = true } }, + }, } end @@ -1479,7 +1483,7 @@ for _, spec in ipairs({ makespec_orgmode(), -- navigation makespec_whichkey(), - makespec_tmuxnav(), + makespec_smartsplits(), makespec_hlslens(), makespec_flash(), makespec_grugfar(), diff --git a/tmux/tmux.conf b/tmux/tmux.conf index c0b6a61..caba6c9 100644 --- a/tmux/tmux.conf +++ b/tmux/tmux.conf @@ -79,12 +79,6 @@ bind i display-panes # Config Reloads bind r source-file ~/.config/tmux/tmux.conf \; refresh-client \; display-message "Config reloaded" -# resize controls -bind -r h resize-pane -L 10 \; display-message "Resize left" -bind -r l resize-pane -R 10 \; display-message "Resize right" -bind -r k resize-pane -U 10 \; display-message "Resize up" -bind -r j resize-pane -D 10 \; display-message "Resize down" - # zoom control bind -n M-o resize-pane -Z @@ -141,27 +135,6 @@ bind q confirm-before -p "kill-pane #P? (y/n)" kill-pane # clear selected pane bind b send-keys -R \; clear-history \; send-keys Enter -# 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|n?vim?x?)(diff)?$'" -bind -n M-h if-shell "$is_vim" "send-keys M-h" "select-pane -L" -bind -n M-j if-shell "$is_vim" "send-keys M-j" "select-pane -D" -bind -n M-k if-shell "$is_vim" "send-keys M-k" "select-pane -U" -bind -n M-l if-shell "$is_vim" "send-keys M-l" "select-pane -R" -bind M-h "select-pane -L" -bind M-j "select-pane -D" -bind M-k "select-pane -U" -bind M-l "select-pane -R" -#bind -n M-\ if-shell "$is_vim" "send-keys M-\\" "select-pane -l" -bind -T copy-mode-vi M-h select-pane -L -bind -T copy-mode-vi M-j select-pane -D -bind -T copy-mode-vi M-k select-pane -U -bind -T copy-mode-vi M-l select-pane -R -#bind -T copy-mode-vi M-\ select-pane -l - -# fzf binding -set -g @tmux-fzf-launch-key 'f' - ###################### ### PLUGINS ### ###################### @@ -170,10 +143,34 @@ set -g @tmux-fzf-launch-key 'f' set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tmux-sensible' set -g @plugin 'tmux-plugins/tmux-yank' -# set -g @plugin 'arcticicestudio/nord-tmux' -# set -g @plugin 'seebi/tmux-colors-solarized' -# set -g @plugin 'jimeh/tmux-themepack' -# set -g @plugin 'wfxr/tmux-power' + + +###################### +### PANE CONTROL ### +###################### + +set -g @plugin 'mrjones2014/smart-splits.nvim' + +# Optional configurations with their default values if omitted: + +set -g @smart-splits_no_wrap '' # to disable wrapping. (any value disables wrapping) + +set -g @smart-splits_move_left_key 'M-h' # key-mapping for navigation. +set -g @smart-splits_move_down_key 'M-j' # --"-- +set -g @smart-splits_move_up_key 'M-k' # --"-- +set -g @smart-splits_move_right_key 'M-l' # --"-- + +set -g @smart-splits_resize_left_key 'C-h' # key-mapping for resizing. +set -g @smart-splits_resize_down_key 'C-j' # --"-- +set -g @smart-splits_resize_up_key 'C-k' # --"-- +set -g @smart-splits_resize_right_key 'C-l' # --"-- + +set -g @smart-splits_resize_step_size '3' # change the step-size for resizing. + +###################### +### THEME ### +###################### + set -g @plugin 'niksingh710/minimal-tmux-status' set -g @minimal-tmux-justify "centre" set -g @minimal-tmux-indicator-str " tmux " @@ -206,5 +203,8 @@ set -g @minimal-tmux-left-arrow "" set -g status-right-length 20 set -g status-left-length 20 -# keep at bottom +###################### +### KEEP AT BOTTOM ### +###################### + run -b '~/.config/tmux/plugins/tpm/tpm'