cursorline and long lines

152 views
Skip to first unread message

Abu Yoav

unread,
Mar 28, 2012, 1:52:57 PM3/28/12
to vim_use
Hi,

I've just started using vim, and enjoy it very much. I've searched a
bit, but could not find an answer to the following. So, if this is
obvious, excuse the newbie...

I am editing a text file (latex). I prefer that each paragraph be a
long line, and that vim wrap the text. That's the usual behaviour, and
that works fine. An option that seems very helpful is cursorline, so I
set it (":set cul"). However, this does not do what I want. Namely,
instead of highlighting the *visual* line I am on, it highlights the
whole paragraph. Is there any way to highlight only the current visual
line I am on? Again, a workaround would be to instruct vim to have
lines of at most 80 characters (say), but I don't want that.

Thanks,

Abu Yoav

Christian Brabandt

unread,
Mar 29, 2012, 1:40:44 AM3/29/12
to vim...@googlegroups.com

Hm, the documentation for 'cul' talks about screenlines, but in my
experience, 'cul' has always been highlighting complete lines. Looks like
a documentation error.
I guess, there is nothing you can do about, except, maybe implement it
yourself:

fu! CursorLine()
if !exists("CL")
hi CL gui=underline term=underline cterm=underline
endif
if !exists("b:matches")
let b:matches = 0
endif
let col = virtcol('.')
let width = winwidth(0)
let screenline = col/width
let start = screenline * width
let end = (screenline+1) * width + 1
if b:matches > 0
sil! call matchdelete(b:matches)
endif
let pat = '\%'. line('.'). 'l\%>'. start. 'v.*\%<'. end. 'v'
let b:matches = matchadd('CL', pat)
endfu
au CursorHold,CursorHoldI * :call CursorLine()

regards,
Christian

Christian Brabandt

unread,
Mar 29, 2012, 1:42:19 AM3/29/12
to vim...@googlegroups.com
On Thu, March 29, 2012 07:40, Christian Brabandt wrote:
> if !exists("CL")

that should have been if !hlexists("CL")

regards,
Christian

Abu Yoav

unread,
Mar 29, 2012, 3:03:59 PM3/29/12
to vim...@googlegroups.com
Hi Christian,

First, thank you very much for the reply!

On the one hand, your solution does indeed work. On the other hand, the time it takes for the underline to update itself to the correct line is really slow. On my machine, about 5 seconds (with the !hlexists("CL") correction, on a very small file). Do you know if there is a parameter I can tune to get this working faster, or is this due to the fact that a script is inherently slow?



regards,
Christian

--
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

Christian Brabandt

unread,
Mar 29, 2012, 3:13:00 PM3/29/12
to vim...@googlegroups.com
Hi Abu!

On Do, 29 M�r 2012, Abu Yoav wrote:

> First, thank you very much for the reply!
>
> On the one hand, your solution does indeed work. On the other hand, the
> time it takes for the underline to update itself to the correct line is
> really slow. On my machine, about 5 seconds (with the !hlexists("CL")
> correction, on a very small file). Do you know if there is a parameter I
> can tune to get this working faster, or is this due to the fact that a
> script is inherently slow?

That is because it waits until the CursorHold/CursorHoldI triggers,
which by default triggers after 'updatetime' seconds (e.g. 4 seconds, if
you haven't tuned it yourself). So try decreasing the 'updatetime'
setting.

See also the help at
:h 'updatetime'
:h 'CursorHold'

regards,
Christian

Christian Brabandt

unread,
Mar 29, 2012, 3:31:46 PM3/29/12
to vim_use, Vim ML
Bram,

On Mi, 28 M�r 2012, Abu Yoav wrote:

[...]


> I am editing a text file (latex). I prefer that each paragraph be a
> long line, and that vim wrap the text. That's the usual behaviour, and
> that works fine. An option that seems very helpful is cursorline, so I
> set it (":set cul"). However, this does not do what I want. Namely,
> instead of highlighting the *visual* line I am on, it highlights the
> whole paragraph. Is there any way to highlight only the current visual
> line I am on? Again, a workaround would be to instruct vim to have
> lines of at most 80 characters (say), but I don't want that.

The help for 'cursorline' says:

,----
| Highlight the screen line of the cursor with CursorLine
`----

While 'cul' has always been highlighting complete lines. Do you think,
this would warrant a new option, that changes 'cul' to only highlight
screen lines or change the option 'cul' to a string option, that can be
set to 'screen' or 'line'?

This might be helpful for long lines (e.g. when editing csv files and
wrap is set).

If not, the documentation should be updated.

regards,
Christian
--
Der Furchtsame erschrickt vor der Gefahr, der Feige in ihr, der Mutige
nach ihr.
-- Jean Paul (eig. Johann Paul Friedrich Richter)

Abu Yoav

unread,
Mar 29, 2012, 3:53:26 PM3/29/12
to vim...@googlegroups.com
Hi Christian,


> That is because it waits until the CursorHold/CursorHoldI triggers,
> which by default triggers after 'updatetime' seconds (e.g. 4 seconds, if
> you haven't tuned it yourself). So try decreasing the 'updatetime'
> setting.
Oh, now I see. I tried changing the last line of the script to
au CursorMoved,CursorMovedI * :call CursorLine()
but now the cursor movement is too slow. I'll find the best option and stick with that.

Thanks again for all the help,

Abu


On Thu, Mar 29, 2012 at 12:13 PM, Christian Brabandt <cbl...@256bit.org> wrote:
Hi Abu!

regards,
Christian

Gary Johnson

unread,
Mar 29, 2012, 6:41:02 PM3/29/12
to vim_use, Vim ML
On 2012-03-29, Christian Brabandt wrote:
> Bram,
>
> On Mi, 28 M�r 2012, Abu Yoav wrote:
>
> [...]
> > I am editing a text file (latex). I prefer that each paragraph be a
> > long line, and that vim wrap the text. That's the usual behaviour, and
> > that works fine. An option that seems very helpful is cursorline, so I
> > set it (":set cul"). However, this does not do what I want. Namely,
> > instead of highlighting the *visual* line I am on, it highlights the
> > whole paragraph. Is there any way to highlight only the current visual
> > line I am on? Again, a workaround would be to instruct vim to have
> > lines of at most 80 characters (say), but I don't want that.
>
> The help for 'cursorline' says:
>
> ,----
> | Highlight the screen line of the cursor with CursorLine
> `----
>
> While 'cul' has always been highlighting complete lines. Do you think,
> this would warrant a new option, that changes 'cul' to only highlight
> screen lines or change the option 'cul' to a string option, that can be
> set to 'screen' or 'line'?
>
> This might be helpful for long lines (e.g. when editing csv files and
> wrap is set).
>
> If not, the documentation should be updated.

Or declare it a bug and fix the behavior to match the documentation.

Regards,
Gary

Christian Brabandt

unread,
Mar 30, 2012, 3:07:52 AM3/30/12
to vim_use, Vim ML

Well, here is a patch, that fixes it. I am not sure, whether this
is a bug and this patch certainly makes 'cul' behave unexpectedly.

Would be good, if some people try it out,
because the screen drawing code looks frightening to me ;)

regards,
Christian

cursorline.diff

Bram Moolenaar

unread,
Mar 30, 2012, 3:35:52 PM3/30/12
to Christian Brabandt, vim_use, Vim ML

Christian Brabandt wrote:

I don't think we should change the current meaning of 'cursorline'.
What the original poster asked for is something else.

Since 'cursorline' is a boolean option we can't change it to be more
than an on/off switch.

That leaves adding Yet Another Option...

- Bram

--
A KNIGHT rides into shot and hacks him to the ground. He rides off.
We stay for a moment on the glade. A MIDDLE-AGED LADY in a C. & A.
twin-set emerges from the trees and looks in horror at the body of her
HUSBAND.
MRS HISTORIAN: FRANK!
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Christian Brabandt

unread,
Mar 31, 2012, 7:12:52 AM3/31/12
to vim_use, Vim ML
Bram,

On Fr, 30 M�r 2012, Bram Moolenaar wrote:
> That leaves adding Yet Another Option...

have you ever thought about providing some kind of a generic option
setting, that could be easily extendible for such small settings.

Something similar to the 'fo' and 'cpo' settings

e.g. set generic=cursorline:screenline
or something? And then when another new minor setting is needed, one
could extend it to something like this:

set generic=cursorline:screenline,foo:foobar

Does that sound reasonable?

Mit freundlichen Gr��en
Christian

Bram Moolenaar

unread,
Mar 31, 2012, 11:46:57 AM3/31/12
to Christian Brabandt, vim_use, Vim ML

Christian Brabandt wrote:

How is this better than adding an option?

--
He was not in the least bit scared to be mashed into a pulp
Or to have his eyes gouged out and his elbows broken;
To have his kneecaps split and his body burned away
And his limbs all hacked and mangled, brave Sir Robin.

Reply all
Reply to author
Forward
0 new messages