wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

copy mode: Support jump-by-occurrence-of-alphabet (f/F/t/T/,/; of Vim)

Open MiSawa opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. The copy-mode-vi of tmux supports following keymappings

; jump-again
F jump-backward <to>
f jump-forward <to>
, jump-reverse
T jump-to-backward <to>
t jump-to-forward <to>

. After trying wezterm, I found that I used these often to move cursor on copy mode. It'd be great if we had wezterm.actions corresponds to these so that migrating from tmux will be easier.

Describe the solution you'd like Have 4 actions

wezterm.action.CopyMode.JumpForward { prev_char = false, timeout_milliseconds = nil }
wezterm.action.CopyMode.JumpBackward { prev_char = false, timeout_milliseconds = nil }
wezterm.action.CopyMode.JumpAgain
wezterm.action.CopyMode.JumpReverse 

. When JumpForward was invoked, it waits for the next keyboard input c, and jumps to the next occurrence of c in the same line. If prev_char is true, it jumps the one char left from c. Similar (but reverse direction) happens with JumpBackward. JumpAgain repeats previous jump with the same input c, and JumpReverse performs the action similar to previous except it's in the reverse direction. Basically it should (mostly) match the behavior of Vim.

Describe alternatives you've considered Instead of creating dedicated actions, maybe create something like wezterm.readChar (if this doesn't exist yet), and let users write an action_callback that calls readChar and jump to the char?

MiSawa avatar Sep 18 '22 12:09 MiSawa

This should be implemented now in main.

It typically takes about an hour before commits are available as nightly builds for all platforms. Linux builds are the fastest to build and are often available within about 20 minutes. Windows and macOS builds take a bit longer.

Please take a few moments to try out the fix and let me know how that works out. You can find the nightly downloads for your system in the wezterm installation docs.

If you prefer to use packages provided by your distribution or package manager of choice and don't want to replace that with a nightly download, keep in mind that you can download portable packages (eg: a .dmg file on macOS, a .zip file on Windows and an .AppImage file on Linux) that can be run without permanently installing or replacing an existing package, and can then simply be deleted once you no longer need them.

If you are eager and can build from source then you may be able to try this out more quickly.

wez avatar Sep 21 '22 02:09 wez

(still needs docs)

wez avatar Sep 21 '22 02:09 wez

Awesome, thank you so much for the swift implementation!

One thing I noticed is that ;/, in Vim are eager to move the cursor position in Vim (as long as the character occurs). In other words, in Vim, (not t/T itself but) ;/, after t/T search ignores the char next to the current position. For example, when the user hit ; multiple times after hitting ta on a text xaaaaaa where x is the current cursor position, it actually moves cursor one character per ; (but ta itself doesn't move the cursor pos). It'd be awesome to mimic this behavior.

Other than that, the implementation worked great for me!

MiSawa avatar Sep 21 '22 14:09 MiSawa

Thanks for the feedback; I think this is now handled equivalently in main!

wez avatar Sep 22 '22 02:09 wez

Thank you for the update! Seems to behave a little bit different from Vim though; in Vim, t/T itself doesn't perform this eager moving, where wezterm does (ref: cpo-;). This would require us to pass an additional flag that indicates if it's invoked by a repetition (;/,) to perform_jump method, and perform the same match on ((jump.prev_char && is_repetition), jump.forward). Please feel free to leave it as is though, if you think it's minor or more sophisticated behavior!

MiSawa avatar Sep 22 '22 05:09 MiSawa

OK, should be good now in main

wez avatar Sep 22 '22 13:09 wez

Confirmed in wezterm 20220922-061514-07675d5d, thank you so much!!

MiSawa avatar Sep 22 '22 13:09 MiSawa

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Feb 03 '23 18:02 github-actions[bot]