tmux: Rudimentary vim's text object simulation

Add non-robust emulation of vim's v_i{w,W,p,quote,'}.

TODO: Is there a better way of doing else-if?
This commit is contained in:
2024-03-21 15:47:10 +01:00
parent 8c33a9bf96
commit 83945840b8

View File

@@ -146,7 +146,44 @@ bind -T copy-mode-vi Escape \
bind -T copy-mode-vi A send -X cancel
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
# Rudimentary text object simulation
# TODO: Breaks when on the beginning or end of the object
bind -T copy-mode-vi i \
if -F "#{selection_present}" {
command-prompt -k -p (operator-pending) {
if -F "#{==:%1,w}" {
# send "boe"
send -X previous-word
send -X other-end
send -X next-word-end
}{ if -F "#{==:%1,W}" {
# send "BoE"
send -X previous-space
send -X other-end
send -X next-space-end
}{ if -F "#{==:%1,p}" {
# send "{j0o}k$"
send -X previous-paragraph
send -X cursor-down
send -X start-of-line
send -X other-end
send -X next-paragraph
send -X cursor-up
send -X end-of-line
}{ if -F '#{==:%1,"}' {
send -X jump-to-backward '"'
send -X other-end
send -X jump-to-forward '"'
}{ if -F "#{==:%1,'}" {
send -X jump-to-backward "'"
send -X other-end
send -X jump-to-forward "'"
}}}}}
}
} {
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