jeffreytse / zsh-vi-mode

💻 A better and friendly vi(vim) mode plugin for ZSH.
MIT License
2.99k stars 103 forks source link

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

Open brainwo opened 2 years ago

brainwo commented 2 years ago

Basic examination

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)

gonubana commented 2 years ago

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

kangadrewie commented 2 years ago

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

kangadrewie commented 2 years ago

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

kangadrewie commented 2 years ago

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

gonubana commented 2 years ago

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.

jeffreytse commented 2 years ago

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

xPMo commented 2 years ago

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:

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.