On 2019-05-13, Ed Peschko wrote:
> Gary,
>
> thanks for this tip, yes it looks like I could use it to do what I
> want but my concern is speed. I don't want to trigger a potentially
> expensive macro each time the cursor moves anytime, just when the line
> number changes.
>
> So perhaps there is a need for CursorLineMoved? I see in vim where I
> might be added, but I haven't contributed patches to vim before, so
> i'm not sure on how to go about it.
I don't think we need Yet Another Event for this special case. The
usual approach to this sort of problem is to make an inexpensive
test early in the process so that you don't spend time considering
cases you don't care about. In this case, you could cache the last
cursor line location and test against that early in the
autocommand command, perhaps something like this:
:let g:prev_line = 0
:au CursorMoved if line('.') != g:prev_line
\ | let g:prev_line = line('.')
\ | " other stuff
\ | endif
Note that you could have just jumped to the same line number in
a different buffer, so you should test the buffer number, too,
perhaps with getcurpos() instead of line() to get both the buffer
number and the line number.
Regards,
Gary