13

I find myself dealing with this issue every time the wrap option is active (in my particular case whenever I'm working with markdown files).

What happens is that, while scrolling up and down the buffer with j and k, the wrapped lines of text (visually forming a paragraph) at the far top and far bottom don't scroll smoothly (i.e. one by one) out of screen. Instead, whole paragraphs disappear and reappear abruptly from and into view, making for a disorienting and annoying effect.

I think a GIF will explain better what happens. Here, I'm just pressing k repeatedly to scroll upwards. Keep an eye on the paragraph near the bottom!

ugh

I got used to this behaviour because I didn't think it was fixable, but then I realized that doesn't happen with physical lines and wrap unset.

Is there a way to tell Vim to scroll out of screen by visual lines instead of physical ones?

ps: Yes, I've mapped my j and k to gj and gk.

1

3 Answers 3

8

That is an issue, that has been often requested but never been implemented. So no, there is no possibility for a better and smoother scrolling, once the lines wrap.

Update: This is no longer entirely true. See @Richs answer for the status as of 2023

2
  • Are you able to provide a link to where this issue has being discussed? I'd like to know more.
    – mrzool
    Aug 26, 2015 at 11:39
  • 1
    here or here Aug 26, 2015 at 13:08
4

I think you are looking for:

set display=lastline

See :help 'display'.

4
  • That kinda worked but I still don't get the smooth, line-by-line scrolling I get when wrap is unset. The behavior now looks actually inconsistent: more gradual (but still not line-by-line) scrolling while going up, and abrupt paragraph appearance when going down (see GIF).
    – mrzool
    Aug 24, 2015 at 19:38
  • Too bad, cause reading the help page that really looked like my option.
    – mrzool
    Aug 24, 2015 at 19:39
  • 2
    According to :help 'scrolljump' I think that the minimum jump you can get is one line when the cursor moves off-screen. But with wrap set as in your case, one line may occupy multiple screen lines.
    – Vitor
    Aug 25, 2015 at 9:42
  • this solved my issue, set display=lastline when on screen it wasnt displaying last line, it was acting wonky, and content wasnt scrolling and displaying with cursor. thanks!
    – blamb
    Mar 30, 2022 at 19:56
3

There is hope!

A new option 'smoothscroll' was added to Vim in version 9.0.0640, to allow nicer scrolling with soft-wrapped lines.

The bad news is that it currently1 doesn't support the gj and gk commands:

NOTE: only partly implemented, currently works with CTRL-E, CTRL-Y and scrolling with the mouse.

1: As of around May 2023

2
  • 1
    No wonder j and k are not supported, they are unrelated to scrolling.
    – romainl
    May 10 at 11:35
  • 1
    @romainl Like the OP, I have j/k mapped to gj/gk. Updated my answer.
    – Rich
    May 10 at 12:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.