scroll by screen line ?

52 views
Skip to first unread message

mckel...@gmail.com

unread,
Aug 4, 2020, 11:53:43 PM8/4/20
to vim_use
Hi,

Is it possible to scroll like <C-e> but have it be virtual/screen line and not whole line ?
I want to have wrap on, but also want to scroll by screen line when I have long lines.
Does anyone know if that is possible ?
Sort of like: j -> gj ; <C-e> -> ???
I suppose I could do the math in a function and go to bottom of screen and gj X times then go back to previous line, col - but does anyone know of a better way ?

thanks for everything vim,
-m

Tony Mechelynck

unread,
Aug 5, 2020, 10:01:01 PM8/5/20
to vim_use
I don't think it is, because the first character at the top of a Vim
window is either the first character of a (file) line, or some
character in a line which is too long for the window. So unless the
current line is too long for the window, Ctrl-Y will show one more
full file line at the top of the window, and Ctrl-E will make one full
file line disappear at the top of the window. Similarly, scrolling by
mouse will always make an integer number of file lines appear or
disappear at the top (again unless the current line is too long for
the window). I believe that this is as much part of the philosophy of
Vim as the fact that all displayable Latin, Greek, Cyrillic, Hebrew,
etc. characters (other than tabs) always occupy exactly the same
amount of height and width no matter the character in all the windows
of a single instance of Vim, including gvim and macvim, and that a
single fullwidth CJK character (no matter which one) always takes up
exactly twice as much space as two "narrow" characters (e.g. Latin,
etc. characters), except that if there is only one character-width
left at the end of a screen line (with 'wrap' on) it will be thrown
off to the next screen line.

AFAIK, to make sure than Vim always scrolls only a single screen line
at a time you would need to set 'nowrap' but of course any line longer
than 'columns' would then be only partly displayed. Me too, I prefer
'wrap' being on except in (g)vimdiff, and sometimes I am surprised
when going to the next line at bottom makes the display jump up by
several lines because a long line has disappeared at top, but I
believe that "Vim is like that".

Oh, there _is_ a possibility (of sorts): by setting 'lines' to 1 (plus
1 for the status line plus 'cmdheight' for the command-line area) you
could always wrap by screen lines, but OTOH it would nullify the
advantage of ":set wrap" so I don't think you would like it. :-P

Best regards,
Tony.

Christian Brabandt

unread,
Aug 6, 2020, 3:42:46 AM8/6/20
to vim_use
Not really possible. I believe there are some plugins that improve this
behaviour like https://github.com/lukelbd/vim-scrollwrapped but it might
be still a bit hacky.

It's been on my list to look into it, but I never came to it.

Best,
Christian
--
Ein erfolgreicher Mann ist ein Mann, der mehr Geld verdient, als seine
Frau ausgeben kann. Eine erfolgreiche Frau ist eine, die einen solchen
Mann findet.

mckel...@gmail.com

unread,
Aug 6, 2020, 11:10:27 AM8/6/20
to vim_use
Hi,

ok, thank you both for the info.

take care,
-m

Anton Shepelev

unread,
Aug 6, 2020, 5:11:24 PM8/6/20
to vim...@googlegroups.com
mckel...:

> Is it possible to scroll like <C-e> but have it be
> virtual/screen line and not whole line ? I want
> to have wrap on, but also want to scroll by screen
> line when I have long lines.

The replies of Tony and Christian show that Vim is
designed for true plain-text files, which means hard
line breaks, and I, for one, fully approve of the
idea. We already have too much pseudo-plain-text
with line per paraphraph: in Usenet, e-mail, and
even certain markup languages including WikiMarkup
and DokuWiki.

May I ask what kind of soft-wrapped text you want to
edit in Vim? In my opinion, comfortable editing of
soft-wrapped text in Vim would require serions modi-
fions -- in order to make it virtually indistin-
guishable from editing hard-wrapped text. As things
stand, I prefer another editor whenever I need to
word with line-per-paragraph text files...

--
Please, do not forward replies to my e-mail.

Graham Lawrence

unread,
Aug 7, 2020, 3:27:22 PM8/7/20
to vim...@googlegroups.com
I use vim exclusively on wrapped text, often up to 5000 characters per line, and find these 3 mappings useful to produce the effect you want.

nmap <DOWN> gj
nmap <UP> gk
nnoremap ^F ^F jjzt

The nmaps  accept leading counts for the number of screen lines you wish to move.  Both ^F are produced by typing ctrl-v ctrl-f, the intent being to move the text down 1 complete page, as vim normally retains the last 2 lines of the previous screen on the new screen with standard ^F

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200807001104.498db60339b522c1b791d0f3%40gmail.com.


--
Graham Lawrence

Anton Shepelev

unread,
Aug 8, 2020, 8:37:26 AM8/8/20
to vim...@googlegroups.com
Graham Lawrence:

> I use vim exclusively on wrapped text, often up to
> 5000 characters per line, and find these 3 map-
> pings useful to produce the effect you want.
>
> nmap <DOWN> gj
> nmap <UP> gk
> nnoremap ^F ^F jjzt

I know and use gj and jk, remapped to j and k, but
didn't know about jjzt. Thanks.

Antoher problem with wrapped text in Vim is that it
tries to display entire lines, leaving part of the
screen lines empty, prefixed with `@'. It annoys me,
too.

Gary Johnson

unread,
Aug 8, 2020, 12:56:25 PM8/8/20
to vim...@googlegroups.com
On 2020-08-08, Anton Shepelev wrote:

> Antoher problem with wrapped text in Vim is that it
> tries to display entire lines, leaving part of the
> screen lines empty, prefixed with `@'. It annoys me,
> too.

I'm not sure, but I think this setting will fix that problem.

set display=lastline

Regards,
Gary

Graham Lawrence

unread,
Aug 8, 2020, 1:15:52 PM8/8/20
to vim...@googlegroups.com, gary clinton
@Anton Shepelev, the Ctrl-F variant I gave you has a fault, if the lines it jj's over are more than 1/2 the screen length each, it in effect skips a page of text. Instead map Ctrl-F to Ljzt instead.

@gary clinton  many thanks for the 'set display+=lastline' tip, those lines of @s have bugged me for years.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.


--
Graham Lawrence

mckel...@gmail.com

unread,
Aug 12, 2020, 9:37:55 AM8/12/20
to vim_use
Hi,

Thanks.  display+=lastline does help.
I've been using a mapping for <Up>/<Down> to gk/gj for a while and this works well.
I also map <C-f>/<C-b> to winheight(0)/2 gj/gk.  I'll look at <C-f>jjzt.

I set these things when editing a type of log files.

take care,
-m

Reply all
Reply to author
Forward
0 new messages