zsh-vi-mode icon indicating copy to clipboard operation
zsh-vi-mode copied to clipboard

Move through wrapped lines using `gj` and `gk`

Open brainwo opened this issue 3 years ago • 7 comments

Basic examination

  • [x] I have read through the README page
  • [x] I have the latest version of zsh-vi-mode
  • [x] I have tested with another terminal program (UXTerm, kitty)

Problem description

Can't get gj and gk to work

Reproduction steps

  1. Having a long one line command wrapped into next line
  2. Try to move up using gk in normal mode
  3. Nothing happens

Expected behavior

Move up and down through the wrapping lines (like what Vim does)

brainwo avatar Jan 13 '22 13:01 brainwo

Just to say that I'm rooting for this feature too.

gonubana avatar Apr 10 '22 17:04 gonubana

Same here - any idea on how this might be done @jeffreytse? We might be able to put in a PR for this feature

kangadrewie avatar Apr 27 '22 16:04 kangadrewie

I've opened a PR to add this in @jeffreytse 😃 Check out #177

kangadrewie avatar Apr 27 '22 17:04 kangadrewie

Looks like my PR has been closed. Owner might have a different approach to doing this

kangadrewie avatar May 06 '22 20:05 kangadrewie

Looks like @kangadrewie's fix didn't accept a count. So neither 3gj nor 2gk would work. There is also a change that looks like a typo in the zvm_escape_non_printed_characters() function.

gonubana avatar May 09 '22 14:05 gonubana

Hi @kangadrewie

Thanks for your contribution, I didn't close your PR, and as @gonubana said, there is a typo in the zvm_escape_non_printed_characters() function. : )

Thanks & Regards

jeffreytse avatar May 09 '22 15:05 jeffreytse

I started looking at this for my own plugin, and it gets super complex if you want to do it totally correctly. You could probably get away with this (accepts count):

zvm_up_visual_line(){
    zle -f vichange
    ((CURSOR += NUMERIC * COLUMNS))
}
zvm_down_visual_line(){
    zle -f vichange
    ((CURSOR -= NUMERIC * COLUMNS))
}

But this only works if:

  • moving with a wrapped line, not between lines
  • that wrapped line doesn't have tab characters

This might be good enough to appease most people; while I use multi-line editing a fair bit (I have a widget which loads a function definition into the buffer, which always is multi-line and tabbed) I'm not sure how much others do. There's an extra complexity which happen when moving to or from the first line, where the prompt isn't accounted for in the visual count.

I'm still writing my more complete implementation, but I think I'lll probably resort to using terminfo[u7] to ask the terminal where the cursor is.

xPMo avatar Jun 25 '22 14:06 xPMo