diff --git a/home/base/programs/nixvim/default.nix b/home/base/programs/nixvim/default.nix index 2676499..826507d 100644 --- a/home/base/programs/nixvim/default.nix +++ b/home/base/programs/nixvim/default.nix @@ -12,6 +12,7 @@ ./plugins/neo-tree.nix ./plugins/which-key.nix ./plugins/project-nvim.nix + ./plugins/smart-splits.nix ./plugins/misc.nix ]; diff --git a/home/base/programs/nixvim/plugins/misc.nix b/home/base/programs/nixvim/plugins/misc.nix index 8f282a1..32d153d 100644 --- a/home/base/programs/nixvim/plugins/misc.nix +++ b/home/base/programs/nixvim/plugins/misc.nix @@ -4,6 +4,5 @@ programs.nixvim.plugins = { nvim-autopairs.enable = true; direnv.enable = true; - tmux-navigator.enable = true; }; } diff --git a/home/base/programs/nixvim/plugins/smart-splits.nix b/home/base/programs/nixvim/plugins/smart-splits.nix new file mode 100644 index 0000000..f8c7b55 --- /dev/null +++ b/home/base/programs/nixvim/plugins/smart-splits.nix @@ -0,0 +1,117 @@ +{ + programs.nixvim = { + plugins.smart-splits = { + enable = true; + settings = { + ignored_events = [ + "BufEnter" + "WinEnter" + ]; + resize_mode = { + quit_key = ""; + resize_keys = [ + "h" + "j" + "k" + "l" + ]; + silent = true; + }; + }; + }; + + keymaps = [ + { + action = "lua require('smart-splits').resize_left()"; + key = ""; + options = { + desc = "Resize split to the left"; + }; + } + { + action = "lua require('smart-splits').resize_down()"; + key = ""; + options = { + desc = "Resize split downwards"; + }; + } + { + action = "lua require('smart-splits').resize_up()"; + key = ""; + options = { + desc = "Resize split upwards"; + }; + } + { + action = "lua require('smart-splits').resize_right()"; + key = ""; + options = { + desc = "Resize split to the right"; + }; + } + { + action = "lua require('smart-splits').move_cursor_left()"; + key = ""; + options = { + desc = "Move cursor to the left split"; + }; + } + { + action = "lua require('smart-splits').move_cursor_down()"; + key = ""; + options = { + desc = "Move cursor to the downward split"; + }; + } + { + action = "lua require('smart-splits').move_cursor_up()"; + key = ""; + options = { + desc = "Move cursor to the upward split"; + }; + } + { + action = "lua require('smart-splits').move_cursor_right()"; + key = ""; + options = { + desc = "Move cursor to the right split"; + }; + } + { + action = "lua require('smart-splits').move_cursor_previous()"; + key = ""; + options = { + desc = "Move cursor to the previous split"; + }; + } + { + action = "lua require('smart-splits').swap_buf_left()"; + key = "h>"; + options = { + desc = "Swap buffer to the left"; + }; + } + { + action = "lua require('smart-splits').swap_buf_down()"; + key = "j>"; + options = { + desc = "Swap buffer downwards"; + }; + } + { + action = "lua require('smart-splits').swap_buf_up()"; + key = "k>"; + options = { + desc = "Swap buffer upwards"; + }; + } + { + action = "lua require('smart-splits').swap_buf_right()"; + key = "l>"; + options = { + desc = "Swap buffer to the right"; + }; + } + ]; + }; +} diff --git a/home/base/programs/wezterm.nix b/home/base/programs/wezterm.nix index 8a9b257..2675190 100644 --- a/home/base/programs/wezterm.nix +++ b/home/base/programs/wezterm.nix @@ -4,13 +4,87 @@ programs.wezterm = { enable = true; extraConfig = '' - local wezterm = require 'wezterm' + local w = require('wezterm') + + -- if you are *NOT* lazy-loading smart-splits.nvim (recommended) + local function is_vim(pane) + -- this is set by the plugin, and unset on ExitPre in Neovim + return pane:get_user_vars().IS_NVIM == 'true' + end + + -- if you *ARE* lazy-loading smart-splits.nvim (not recommended) + -- you have to use this instead, but note that this will not work + -- in all cases (e.g. over an SSH connection). Also note that + -- `pane:get_foreground_process_name()` can have high and highly variable + -- latency, so the other implementation of `is_vim()` will be more + -- performant as well. + local function is_vim(pane) + -- This gsub is equivalent to POSIX basename(3) + -- Given "/foo/bar" returns "bar" + -- Given "c:\\foo\\bar" returns "bar" + local process_name = string.gsub(pane:get_foreground_process_name(), '(.*[/\\])(.*)', '%2') + return process_name == 'nvim' or process_name == 'vim' + end + + local direction_keys = { + h = 'Left', + j = 'Down', + k = 'Up', + l = 'Right', + } + + local function split_nav(resize_or_move, key) + return { + key = key, + mods = resize_or_move == 'resize' and 'META' or 'CTRL', + action = w.action_callback(function(win, pane) + if is_vim(pane) then + -- pass the keys through to vim/nvim + win:perform_action({ + SendKey = { key = key, mods = resize_or_move == 'resize' and 'META' or 'CTRL' }, + }, pane) + else + if resize_or_move == 'resize' then + win:perform_action({ AdjustPaneSize = { direction_keys[key], 3 } }, pane) + else + win:perform_action({ ActivatePaneDirection = direction_keys[key] }, pane) + end + end + end), + } + end return { - front_end = "WebGpu", - enable_tab_bar = false, - enable_wayland = false, - harfbuzz_features = { "ss01", "ss03" }, + front_end = "WebGpu", + hide_tab_bar_if_only_one_tab = true, + show_new_tab_button_in_tab_bar = false, + enable_wayland = false, + harfbuzz_features = { "ss01", "ss03" }, + + leader = { key = " ", mods = "CTRL", timeout_milliseconds = 1000 }, + + keys = { + { + mods = "LEADER", + key = "-", + action = wezterm.action.SplitVertical { domain = "CurrentPaneDomain" } + }, + { + mods = "LEADER", + key = "=", + action = wezterm.action.SplitHorizontal { domain = "CurrentPaneDomain" } + }, + -- move between split panes + split_nav('move', 'h'), + split_nav('move', 'j'), + split_nav('move', 'k'), + split_nav('move', 'l'), + -- resize panes + split_nav('resize', 'h'), + split_nav('resize', 'j'), + split_nav('resize', 'k'), + split_nav('resize', 'l'), + }, } ''; }; diff --git a/home/base/shell/default.nix b/home/base/shell/default.nix index 2d4d1eb..768e9b0 100644 --- a/home/base/shell/default.nix +++ b/home/base/shell/default.nix @@ -6,7 +6,6 @@ ./starship.nix ./zoxide.nix ./direnv.nix - ./tmux.nix ./zellij.nix ]; } diff --git a/home/base/shell/fish.nix b/home/base/shell/fish.nix index d3cf4ff..68cc18d 100644 --- a/home/base/shell/fish.nix +++ b/home/base/shell/fish.nix @@ -16,7 +16,7 @@ in fish_vi_key_bindings # Enable Vi mode fish_config theme choose "Catppuccin Frappe" ''; - shellAbbrs = { cd = "z"; ngc = "sudo nix-collect-garbage -d"; tmux = "tmux new -A -s main"; }; + shellAbbrs = { cd = "z"; ngc = "sudo nix-collect-garbage -d"; }; plugins = [ { name = "fzf"; src = pkgs.fishPlugins.fzf.src; } ]; }; diff --git a/home/base/shell/tmux.nix b/home/base/shell/tmux.nix deleted file mode 100644 index 3c78387..0000000 --- a/home/base/shell/tmux.nix +++ /dev/null @@ -1,46 +0,0 @@ -{ pkgs, ... }: - -{ - programs.tmux = { - enable = true; - prefix = "C-space"; - escapeTime = 10; - clock24 = true; - keyMode = "vi"; - mouse = true; - baseIndex = 1; - extraConfig = '' - set-option -a terminal-features "''${TERM}:RGB" - ''; - plugins = with pkgs; [ - { - plugin = tmuxPlugins.catppuccin; - extraConfig = '' - set -g @catppuccin_window_left_separator "" - set -g @catppuccin_window_right_separator " " - set -g @catppuccin_window_middle_separator " █" - set -g @catppuccin_window_number_position "right" - - set -g @catppuccin_window_default_fill "number" - set -g @catppuccin_window_default_text "#W" - - set -g @catppuccin_window_current_fill "number" - set -g @catppuccin_window_current_text "#W" - - set -g @catppuccin_status_modules_right "directory user host session" - set -g @catppuccin_status_left_separator " " - set -g @catppuccin_status_right_separator "" - set -g @catppuccin_status_fill "icon" - set -g @catppuccin_status_connect_separator "no" - - set -g @catppuccin_directory_text "#{pane_current_path}" - - set -g @catppuccin_flavor 'frappe' - ''; - } - tmuxPlugins.vim-tmux-navigator - tmuxPlugins.yank - ]; - }; - programs.fzf.tmux.enableShellIntegration = true; -}