Skip to content

feat: H/M/L Vim-like motion for moving cursor relative to viewport#3970

Merged
sxyazi merged 2 commits into
sxyazi:mainfrom
SpiritCroc:window-movement
Jun 24, 2026
Merged

feat: H/M/L Vim-like motion for moving cursor relative to viewport#3970
sxyazi merged 2 commits into
sxyazi:mainfrom
SpiritCroc:window-movement

Conversation

@SpiritCroc

@SpiritCroc SpiritCroc commented May 17, 2026

Copy link
Copy Markdown
Contributor

Introduce a new vp step unit, that allows you to move the cursor to relative position based on the items currently rendered on viewport, 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 = "H", run = "arrow 0vp",   desc = "High: Move cursor to visible viewport top" },
{ on = "M", run = "arrow 50vp",  desc = "Middle: Move cursor to visible viewport center" },
{ on = "L", run = "arrow 100vp", desc = "Low: Move cursor to visible viewport bottom" },

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.

Comment thread yazi-actor/src/mgr/arrow.rs Outdated
Comment thread yazi-core/src/tab/folder.rs Outdated
@sxyazi

sxyazi commented May 17, 2026

Copy link
Copy Markdown
Owner

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
Contributor 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
Contributor 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
Introduce a new `vp` step unit, 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 = "H", run = "arrow 0vp",   desc = "High: Move cursor to visible viewport top" },
{ on = "M", run = "arrow 50vp",  desc = "Middle: Move cursor to visible viewport center" },
{ on = "L", run = "arrow 100vp", desc = "Low: Move cursor to visible viewport bottom" },
```
@sxyazi sxyazi force-pushed the window-movement branch from db32243 to 6c458ca Compare June 24, 2026 09:35
@sxyazi sxyazi changed the title Support moving arrow relative to window, similar to H/M/L vim motions feat: H/M/L Vim-like motion for moving cursor relative to viewport Jun 24, 2026

@sxyazi sxyazi left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ty!

@sxyazi sxyazi merged commit b1ee2e7 into sxyazi:main Jun 24, 2026
6 checks passed
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