Skip to content

Commit

Permalink
home: tmux-vim pane navigator config
Browse files Browse the repository at this point in the history
  • Loading branch information
adfaure committed May 24, 2024
1 parent 2fd20f6 commit 3d46fa1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
4 changes: 0 additions & 4 deletions homes/modules/tmux/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ in {
bind-key C-h display-popup -E -h 75% -w 75% -d "#{pane_current_path}" "${pkgs.zenith}/bin/zenith"
bind-key C-s display-popup -E -h 75% -w 75% -d "#{pane_current_path}" "(tmux new-session -s scratch -d && tmux new-window -t scratch:4 'nvim "+:ObsidianToday"'); tmux a -t scratch:1"
# bind-key C-p display-popup -E -h 75% -w 75% -d "#{pane_current_path}" "tmux attach -t scratch:2"
# bind-key C-r display-popup -E -h 75% -w 75% -d "#{pane_current_path}" "tmux attach -t scratch:3"
bind-key C-j display-popup -E -h 75% -w 75% -d "#{pane_current_path}" "tmux attach -t scratch:4"
'';
};

home.packages = with pkgs; [];
}
46 changes: 46 additions & 0 deletions homes/modules/vim-tmux-panes/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{ lib, config, pkgs, ... }:
let
inherit (lib) mkEnableOption mkIf;
cfg = config.adfaure.home-modules.vim-tmux-nav-conf;
in {
options.adfaure.home-modules.vim-tmux-nav-conf = {
enable = mkEnableOption "vim-tmux-nav-conf";
};

config = mkIf cfg.enable {
programs.tmux.extraConfig = ''
# 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|l?n?vim?x?|fzf)(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'
tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'
if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\' 'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
"bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\' 'select-pane -l'"
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
bind-key -T copy-mode-vi 'C-\' select-pane -l
'';

programs.neovim = {
extraConfig = ''
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <C-H> :<C-U>TmuxNavigateLeft<cr>
nnoremap <silent> <C-J> :<C-U>TmuxNavigateDown<cr>
nnoremap <silent> <C-K> :<C-U>TmuxNavigateUp<cr>
nnoremap <silent> <C-L> :<C-U>TmuxNavigateRight<cr>
'';

plugins = [ pkgs.vimPlugins.vim-tmux-navigator ];
};
};
}
4 changes: 3 additions & 1 deletion homes/modules/vim/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ in {
# vimAlias = true;
# withPython3 = true;
# https://github.com/nix-community/home-manager/issues/1712
extraConfig = builtins.readFile "${my-dotfiles}/files/vimrc";

extraConfig = (builtins.readFile "${my-dotfiles}/files/vimrc");

extraLuaConfig = builtins.readFile ./init.lua;
plugins = my_vim_plugins.plugins;
# extraPackages = with pkgs;
Expand Down

0 comments on commit 3d46fa1

Please sign in to comment.