From 4e8ab80c6625dd59d9c004029ebeef9c3df62265 Mon Sep 17 00:00:00 2001 From: Julian Prein Date: Thu, 4 Jul 2024 15:33:28 +0200 Subject: [PATCH] tmux: Fix edge cases in paragraph text-object Also add comments explaining the history & pane position checks in the C-y and C-e bindings, since I used those and had to rethink about what they're doing. --- .config/tmux/tmux.conf | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index 7b0982d..2786eda 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -176,11 +176,19 @@ bind -T copy-mode-vi i \ }{ if -F "#{==:%1,p}" { # send "{j0o}k$" send -X previous-paragraph - send -X cursor-down + # don't move down if we're at the very first + # paragraph + if -F "#{||:#{e|<:#{scroll_position},#{history_size}},#{e|>:#{copy_cursor_y},#{scroll_region_upper}}}" { + send -X cursor-down + } send -X start-of-line send -X other-end send -X next-paragraph - send -X cursor-up + # don't move up if we're at the very last + # paragraph + if -F "#{||:#{e|>:#{scroll_position},0},#{e|<:#{copy_cursor_y},#{scroll_region_lower}}}" { + send -X cursor-up + } send -X end-of-line }{ if -F '#{==:%1,"}' { send -X jump-to-backward '"' @@ -201,16 +209,20 @@ bind -T copy-mode-vi i \ # 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 \ + # check that there is still history beneath to scroll to. if -F "#{e|>:#{scroll_position},0}" { send-keys -X scroll-down + # check that the cursor is not at the top of the pane if -F "#{e|>:#{copy_cursor_y},#{scroll_region_upper}}" { send-keys -X cursor-up } } bind -T copy-mode-vi C-y \ + # check that there is still history above to scroll to. if -F "#{e|<:#{scroll_position},#{history_size}}" { send-keys -X scroll-up + # check that the cursor is not at the bottom of the pane if -F "#{e|<:#{copy_cursor_y},#{scroll_region_lower}}" { send-keys -X cursor-down }