Allow seamless navigation between vim and tmux splits
This commit is contained in:
parent
758e624b07
commit
701bd244be
6 changed files with 40 additions and 8 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -19,3 +19,6 @@
|
|||
[submodule "tmux/.tmux/plugins/tmux-cmd-capture"]
|
||||
path = tmux/.tmux/plugins/tmux-cmd-capture
|
||||
url = https://github.com/artemave/tmux_capture_last_command_output.git
|
||||
[submodule "tmux/.tmux/plugins/vim-tmux-navigator"]
|
||||
path = tmux/.tmux/plugins/vim-tmux-navigator
|
||||
url = https://github.com/christoomey/vim-tmux-navigator.git
|
||||
|
|
|
@ -93,6 +93,11 @@ vim.g.clipboard = {
|
|||
cache_enabled = true
|
||||
}
|
||||
|
||||
-- No default mappings for tmux navigator
|
||||
vim.g.tmux_navigator_no_mappings = 1
|
||||
-- Write the current buffer, but only if changed before navigating from Vim to tmux pane
|
||||
vim.g.tmux_navigator_save_on_switch = 1
|
||||
|
||||
-- We do this to prevent the loading of the system fzf.vim plugin. This is
|
||||
-- present at least on Arch/Manjaro
|
||||
vim.api.nvim_command('set rtp-=/usr/share/vim/vimfiles')
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
local remap = vim.api.nvim_set_keymap
|
||||
local expr_opts = { noremap=true, unique=true, expr=true }
|
||||
local silent_opts = { noremap=true, unique=true, silent=true }
|
||||
local opts = { noremap=true, unique=true }
|
||||
|
||||
remap('c', '<Esc>', '<C-C>', opts)
|
||||
|
@ -144,3 +145,9 @@ remap('n', ',D', '<cmd>lua vim.diagnostic.open_float(0, {scope="cursor"})<CR>',
|
|||
remap('n', '<Leader>dc', ':DiffConflicts<CR>' , opts)
|
||||
remap('n', '<Leader>ds', ':DiffConflictsShowHistory<CR>', opts)
|
||||
remap('n', '<Leader>dw', ':DiffConflictsWithHistory<CR>', opts)
|
||||
|
||||
-- Tmux pane and nvim window switching
|
||||
remap('n', '<C-Left>' , ':TmuxNavigateLeft<CR>' , silent_opts)
|
||||
remap('n', '<C-Right>', ':TmuxNavigateRight<CR>', silent_opts)
|
||||
remap('n', '<C-Up>' , ':TmuxNavigateUp<CR>' , silent_opts)
|
||||
remap('n', '<C-Down>' , ':TmuxNavigateDown<CR>' , silent_opts)
|
||||
|
|
|
@ -101,6 +101,7 @@ local init = function ()
|
|||
'chentau/marks.nvim',
|
||||
}
|
||||
use 'andymass/vim-matchup'
|
||||
use 'christoomey/vim-tmux-navigator'
|
||||
end
|
||||
|
||||
return require('packer').startup(init)
|
||||
|
|
|
@ -35,11 +35,26 @@ set-option -g allow-rename off
|
|||
set -g mouse on
|
||||
set -g focus-events on
|
||||
|
||||
# Use Ctrl-arrow keys without prefix key to switch panes
|
||||
bind -n C-Left select-pane -L
|
||||
bind -n C-Right select-pane -R
|
||||
bind -n C-Up select-pane -U
|
||||
bind -n C-Down select-pane -D
|
||||
# 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-key -n 'C-Left' if-shell "$is_vim" 'send-keys C-Left' 'select-pane -L'
|
||||
bind-key -n 'C-Down' if-shell "$is_vim" 'send-keys C-Down' 'select-pane -D'
|
||||
bind-key -n 'C-Up' if-shell "$is_vim" 'send-keys C-Up' 'select-pane -U'
|
||||
bind-key -n 'C-Right' if-shell "$is_vim" 'send-keys C-Right' '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-Left' select-pane -L
|
||||
bind-key -T copy-mode-vi 'C-Down' select-pane -D
|
||||
bind-key -T copy-mode-vi 'C-Up' select-pane -U
|
||||
bind-key -T copy-mode-vi 'C-Right' select-pane -R
|
||||
|
||||
# Pane resizing with arrow keys
|
||||
bind Left resize-pane -L 10
|
||||
|
|
1
tmux/.tmux/plugins/vim-tmux-navigator
Submodule
1
tmux/.tmux/plugins/vim-tmux-navigator
Submodule
|
@ -0,0 +1 @@
|
|||
Subproject commit 9ca5bfe5bd274051b5dd796cc150348afc993b80
|
Loading…
Reference in a new issue