Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In vim, how to scroll, continuously, by screen lines when wrapping is enabled?

Tags:

I can get the bottom of the window to display partial lines by setting display=lastline

Is there a similar option that would allow partial lines to be displayed at the top of a window?

Without this functionality, my vim still scrolls (down) by more than 1 screen line when the topmost file line being displayed is wrapped into multiple screen lines.

For example, in the following scenario, when I press C-E, my vim will scroll down by 3 screen lines. Is there a way to make it scroll by only 1 screen line such that only the first two words in line 1 are hidden, but the following 3 words are still displayed? This will be very useful for editing long paragraphs of text.

Note: I'm referring to the scrolling of the entire screen, not the movement of cursor.

------------------
1 abcdefg abcefg
  abcasdfsa sdfsf
  sdfc
2 adfadf
3 adfadf
4 adfadf
------------------
like image 901
neuron Avatar asked Dec 03 '11 16:12

neuron


People also ask

How do I scroll down a page in Vim?

You can make Vim scroll the text using the shifted up/down arrows by mapping Shift-Up to Ctrl-Y and Shift-Down to Ctrl-E. Shift-Down will then scroll down (like moving a scroll-bar down, or like moving a cursor at the bottom of a window down), and Shift-Up will then scroll up (like moving a scroll-bar up, etc).


Video Answer


1 Answers

I don't think it is possible to do exactly what you want.

Here's the description I get when I type :help CTRL-E

                                                             CTRL-E
CTRL-E                      Scroll windows [count] lines downwards in the buffer.
                            Mnemonic: Extra lines.

Note that while it says it is scrolling the window, it also mentions that it is scrolling lines in the buffer. You really are scrolling only one (wrapped) line at a time.

I don't think there's another way around this.

I can get the bottom of the window to display partial lines by setting display=lastline

I think display=lastline is a false solution - you still scroll the same amount, you just have more visible.

The real way to solve this is to disable wrapping:

:set nowrap

Edit

Some related threads that show that a "scrolling via screen lines" feature is under consideration, but will take a while to be implemented:

  • http://vim.1045645.n5.nabble.com/Feature-request-Display-partial-paragraph-at-the-top-of-the-window-td1166809.html (4 years ago)
  • http://vim.1045645.n5.nabble.com/Scrolling-screen-lines-I-knew-it-s-impossible-td3358342.html (the beginning of this year. Same dev mentioned wanting to implement it: "Ben Schmidt")
like image 54
Merlyn Morgan-Graham Avatar answered Sep 23 '22 18:09

Merlyn Morgan-Graham