Improves nvim/tmux navigation

main
zoomiti 4 months ago
parent 2bd1d651ab
commit cd40be72fc

@ -178,7 +178,44 @@ require "pack".add({
} }
} }
}, },
"christoomey/vim-tmux-navigator" {
"alexghergh/nvim-tmux-navigation",
-- {{{ nvim-tmux-navigation config
config = function()
local nvim_tmux_nav = require('nvim-tmux-navigation')
nvim_tmux_nav.setup {
disable_when_zoomed = true -- defaults to false
}
vim.keymap.set('n', "<C-\\>", nvim_tmux_nav.NvimTmuxNavigateLastActive)
vim.keymap.set('n', "<C-Space>", nvim_tmux_nav.NvimTmuxNavigateNext)
-- Custom keymaps that work with your Ctrl-w workflow
vim.keymap.set('n', '<C-w><C-h>', nvim_tmux_nav.NvimTmuxNavigateLeft, { desc = 'Navigate left' })
vim.keymap.set('n', '<C-w><C-j>', nvim_tmux_nav.NvimTmuxNavigateDown, { desc = 'Navigate down' })
vim.keymap.set('n', '<C-w><C-k>', nvim_tmux_nav.NvimTmuxNavigateUp, { desc = 'Navigate up' })
vim.keymap.set('n', '<C-w><C-l>', nvim_tmux_nav.NvimTmuxNavigateRight, { desc = 'Navigate right' })
-- Also support single letters after Ctrl-w (like standard Vim)
vim.keymap.set('n', '<C-w>h', nvim_tmux_nav.NvimTmuxNavigateLeft, { desc = 'Navigate left' })
vim.keymap.set('n', '<C-w>j', nvim_tmux_nav.NvimTmuxNavigateDown, { desc = 'Navigate down' })
vim.keymap.set('n', '<C-w>k', nvim_tmux_nav.NvimTmuxNavigateUp, { desc = 'Navigate up' })
vim.keymap.set('n', '<C-w>l', nvim_tmux_nav.NvimTmuxNavigateRight, { desc = 'Navigate right' })
vim.keymap.set('n', '<C-w><Left>', nvim_tmux_nav.NvimTmuxNavigateLeft, { desc = 'Navigate left' })
vim.keymap.set('n', '<C-w><Down>', nvim_tmux_nav.NvimTmuxNavigateDown, { desc = 'Navigate down' })
vim.keymap.set('n', '<C-w><Up>', nvim_tmux_nav.NvimTmuxNavigateUp, { desc = 'Navigate up' })
vim.keymap.set('n', '<C-w><Right>', nvim_tmux_nav.NvimTmuxNavigateRight, { desc = 'Navigate right' })
-- Previous pane/split
vim.keymap.set('n', '<C-w><C-w>', nvim_tmux_nav.NvimTmuxNavigateLastActive,
{ desc = 'Navigate to previous' })
vim.keymap.set('n', '<C-w>w', nvim_tmux_nav.NvimTmuxNavigateLastActive,
{ desc = 'Navigate to previous' })
end
-- }}}
}
}) })
vim.opt.number = true vim.opt.number = true
@ -244,14 +281,7 @@ vim.keymap.set('n', '<leader>w', '<CMD>write<CR>', { desc = "Write File" })
-- {{{ Terminal Mode -- {{{ Terminal Mode
vim.keymap.set('t', '<ESC>', '<C-\\><C-n>') vim.keymap.set('t', '<ESC>', '<C-\\><C-n>')
vim.keymap.set('t', '<C-W>h', '<C-\\><C-n><C-W>h') vim.keymap.set('t', '<C-w>', '<C-\\><C-n><C-w>')
vim.keymap.set('t', '<C-W>j', '<C-\\><C-n><C-W>j')
vim.keymap.set('t', '<C-W>k', '<C-\\><C-n><C-W>k')
vim.keymap.set('t', '<C-W>l', '<C-\\><C-n><C-W>l')
vim.keymap.set('t', '<C-W><Left>', '<C-\\><C-n><C-W><Left>')
vim.keymap.set('t', '<C-W><Down>', '<C-\\><C-n><C-W><Down>')
vim.keymap.set('t', '<C-W><Up>', '<C-\\><C-n><C-W><Up>')
vim.keymap.set('t', '<C-W><Right>', '<C-\\><C-n><C-W><Right>')
vim.api.nvim_create_autocmd('BufEnter', { pattern = 'term://*', command = 'startinsert' }) vim.api.nvim_create_autocmd('BufEnter', { pattern = 'term://*', command = 'startinsert' })
vim.api.nvim_create_autocmd('TermOpen', { vim.api.nvim_create_autocmd('TermOpen', {
callback = function(args) callback = function(args)

@ -4,6 +4,7 @@ bind r source-file ~/.tmux.conf
unbind C-b unbind C-b
set -g prefix C-s set -g prefix C-s
bind C-s send-prefix bind C-s send-prefix
bind C-w send-keys C-w
set -g mouse on set -g mouse on
@ -17,6 +18,8 @@ set -g pane-base-index 1
# Renumber windows when a window is closed # Renumber windows when a window is closed
set -g renumber-windows on set -g renumber-windows on
set -g set-clipboard on
# Status Line # Status Line
set-option -g status-position top set-option -g status-position top
set -g status-bg black set -g status-bg black
@ -27,45 +30,64 @@ set -g pane-border-style fg=brightblack
set -g pane-active-border-style fg=yellow set -g pane-active-border-style fg=yellow
set -g message-style bg=yellow,fg=black,bold set -g message-style bg=yellow,fg=black,bold
# Background color logic
bg_color="#{?#{==:#{client_key_table},VIMLIKE},brightmagenta,#{?client_prefix,brightblue,yellow}}"
# Text logic
status_text="#{?#{==:#{client_key_table},VIMLIKE}, WINDOW,#{?client_prefix, PREFIX, NORMAL}}"
# Left side - yellow section with session, transition to gray # Left side - yellow section with session, transition to gray
set -g status-left "#[fg=black,bg=brightblue,bold]#{?client_prefix, PREFIX,#[fg=black,bg=yellow,bold] NORMAL} #[fg=black,bg=white] #S " set -g status-left "#[fg=black,bg=${bg_color},bold]${status_text} #[fg=black,bg=white] #S "
# Right side # Right side
set -g status-right "#(whoami)@#h #{?client_utf8,| utf-8,} #[fg=black,bg=white] %I:%M %p | %b %d #[fg=black,bg=brightblue]#{?client_prefix,,#[fg=black,bg=yellow,bold]} #I:#P " set -g status-right "#(whoami)@#h #{?client_utf8,| utf-8,} #[fg=black,bg=white] %I:%M %p | %b %d #[fg=black,bg=${bg_color}] #I:#P "
# Window list in the gray middle section # Window list in the gray middle section
set -g window-status-format " #I #W " set -g window-status-format " #I #W "
set -g window-status-current-format "#[fg=brightblue,bg=black,bold]#{?client_prefix,,#[fg=yellow,bg=black,bold]}[#I #W]" set -g window-status-current-format "#[fg=${bg_color},bg=black,bold][#I #W]"
set -g window-status-separator "" set -g window-status-separator ""
# Smart pane switching with awareness of Vim splits
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
| grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(diff)?$'"
# Ctrl-w prefix
bind -n C-w switch-client -T VIMLIKE
# Navigation that works with both tmux and vim
bind -T VIMLIKE C-h if-shell "$is_vim" 'send-keys C-w C-h' 'select-pane -L'
bind -T VIMLIKE C-j if-shell "$is_vim" 'send-keys C-w C-j' 'select-pane -D'
bind -T VIMLIKE C-k if-shell "$is_vim" 'send-keys C-w C-k' 'select-pane -U'
bind -T VIMLIKE C-l if-shell "$is_vim" 'send-keys C-w C-l' 'select-pane -R'
bind -T VIMLIKE h if-shell "$is_vim" 'send-keys C-w h' 'select-pane -L'
bind -T VIMLIKE j if-shell "$is_vim" 'send-keys C-w j' 'select-pane -D'
bind -T VIMLIKE k if-shell "$is_vim" 'send-keys C-w k' 'select-pane -U'
bind -T VIMLIKE l if-shell "$is_vim" 'send-keys C-w l' 'select-pane -R'
bind -T VIMLIKE Left if-shell "$is_vim" 'send-keys C-w Left' 'select-pane -L'
bind -T VIMLIKE Down if-shell "$is_vim" 'send-keys C-w Down' 'select-pane -D'
bind -T VIMLIKE Up if-shell "$is_vim" 'send-keys C-w Up' 'select-pane -U'
bind -T VIMLIKE Right if-shell "$is_vim" 'send-keys C-w Right' 'select-pane -R'
# Window management
bind -T VIMLIKE v if-shell "$is_vim" 'send-keys C-w v' 'split-window -h -c "#{pane_current_path}"' # vertical split
bind -T VIMLIKE s if-shell "$is_vim" 'send-keys C-w s' 'split-window -v -c "#{pane_current_path}"' # horizontal split
bind -T VIMLIKE c if-shell "$is_vim" 'send-keys C-w c' 'new-window -c "#{pane_current_path}"' # new window
bind -T VIMLIKE q if-shell "$is_vim" 'send-keys C-w q' 'kill-pane' # close pane
bind -T VIMLIKE o if-shell "$is_vim" 'send-keys C-w o' 'kill-pane -a' # only this pane
# Resizing
bind -T VIMLIKE + if-shell "$is_vim" 'send-keys C-w +' 'resize-pane -U 5'
bind -T VIMLIKE - if-shell "$is_vim" 'send-keys C-w -' 'resize-pane -D 5'
bind -T VIMLIKE < if-shell "$is_vim" 'send-keys C-w <' 'resize-pane -L 5'
bind -T VIMLIKE > if-shell "$is_vim" 'send-keys C-w >' 'resize-pane -R 5'
bind -T VIMLIKE = if-shell "$is_vim" 'send-keys C-w =' 'select-layout even-horizontal'
# Smart pane switching with awareness of Vim splits. # Movement between windows
# See: https://github.com/christoomey/vim-tmux-navigator bind -T VIMLIKE C-w if-shell "$is_vim" 'send-keys C-w C-w' 'last-window' # Ctrl-w Ctrl-w
bind -T VIMLIKE w if-shell "$is_vim" 'send-keys C-w w' 'last-window' # Ctrl-w w
# decide whether we're in a Vim process
# is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
# | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(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
# List of plugins # List of plugins
set -g @plugin 'tmux-plugins/tpm' set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'christoomey/vim-tmux-navigator'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf) # Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm' run '~/.tmux/plugins/tpm/tpm'

Loading…