Skip to content

Support moving arrow relative to window, similar to H/M/L vim motions#3970

Open
SpiritCroc wants to merge 2 commits into
sxyazi:mainfrom
SpiritCroc:window-movement
Open

Support moving arrow relative to window, similar to H/M/L vim motions#3970
SpiritCroc wants to merge 2 commits into
sxyazi:mainfrom
SpiritCroc:window-movement

Conversation

@SpiritCroc
Copy link
Copy Markdown

Introduce a new PercentWindow step type, that allows you to move the cursor to relative position based on the items currently rendered on screen, similar as H/M/L ("high", "middle", "low") would do in vim.

Not added to default keybinding config since there are some conflicts, but you can put following to override:

{ on = "<S-H>", run = "arrow 0%-window", desc = "High: Move cursor to visible window top without scrolling" },
{ on = "<S-M>", run = "arrow 50%-window", desc = "Middle: Move cursor to visible window center" },
{ on = "<S-L>", run = "arrow 100%-window", desc = "Low: Move cursor to visible window bottom without scrolling" },

Which issue does this PR resolve?

#3969

Rationale of this PR

I got used to moving my cursor with "H"/"M"/"L" key bindings in applications supporting vim like motions. Since switching to yazi recently it has been constantly tripping me, that it is not possible to do.

AI disclaimer

I did use AI to write this for me. This means while I did read the code, question some AI decisions and iterated on them, and of course tested this myself, it's fair to point out I'm not an expert in this codebase.

Introduce a new PercentWindow step type, that allows you to move the
cursor to relative position based on the items currently rendered on
screen, similar as H/M/L ("high", "middle", "low") would do in vim.

Not added to default keybinding config since there are some conflicts,
but you can put following to override:

```
{ on = "<S-H>", run = "arrow 0%-window", desc = "High: Move cursor to visible window top without scrolling" },
{ on = "<S-M>", run = "arrow 50%-window", desc = "Middle: Move cursor to visible window center" },
{ on = "<S-L>", run = "arrow 100%-window", desc = "Low: Move cursor to visible window bottom without scrolling" },
```
Comment thread yazi-actor/src/mgr/arrow.rs Outdated
Comment thread yazi-core/src/tab/folder.rs Outdated
@sxyazi
Copy link
Copy Markdown
Owner

sxyazi commented May 17, 2026

This implementation looks wrong as it doesn't respect scrolloff, e.g. with scrolloff=5:

  • H should jump to the 6th line within the window, not to the first line
  • similarly, L should jump to the 6th-from-last line, not the last line.

Here's how Neovim behaves for H and L when you set :set scrolloff=5:

JtAlVouL.mp4

The same behavior can be reproduced in Vim too.

@SpiritCroc
Copy link
Copy Markdown
Author

Ohhhh that makes sense, I never used scrolloff on (neo)vim, so it was off-putting for me and I worked around it for this change, sounds like I can simplify the patch then 👍

@SpiritCroc
Copy link
Copy Markdown
Author

Hope I got the behaviour correct now.
BTW Thank you for the quick feedback, and for creating/maintaining yazi in the first place, greatly appreciated!

@sxyazi sxyazi force-pushed the main branch 6 times, most recently from 00e4151 to 7a51626 Compare May 28, 2026 04:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants