tmux: Better simulate vim's C-e & C-y

Keep the cursor position or selection while scrolling.
This commit is contained in:
2023-06-14 10:56:08 +02:00
parent e6509c2651
commit 998c1c3fda

View File

@@ -112,6 +112,28 @@ bind -T copy-mode-vi I send -X cancel
bind -T copy-mode-vi a send -X cancel
bind -T copy-mode-vi i send -X cancel
# Simulate vim's C-e & C-y (Keep cursor position while scrolling). As tmux
# cannot scroll past the first and last history line, both bindings stop
# scrolling when the respective line is visible. This mimics the behaviour of
# vim's C-y at the top of the file.
bind -T copy-mode-vi C-e \
if -F "#{>:#{scroll_position},0}" {
send-keys -X scroll-down
if -F "#{>:#{copy_cursor_y},#{scroll_region_upper}}" {
send-keys -X cursor-up
}
}
# TODO: C-y bugs shortly after the start for a couple of lines. I have no idea
# why, but I think the problem lays in the first if, as nothing happens at all
bind -T copy-mode-vi C-y \
if -F "#{<:#{scroll_position},#{history_size}}" {
send-keys -X scroll-up
if -F "#{<:#{copy_cursor_y},#{scroll_region_lower}}" {
send-keys -X cursor-down
}
}
# Navigate panes with <prefix>-[hjkl]
# NOTE: C-[hjkl] (w/o prefix) moves through vim splits and tmux panes
# See vim-tmux-navigator