Saturday, December 26, 2009

Re: cursorline/cursorcolumn highlighting

On 2009-12-26, Bee wrote:
> Gary Johnson wrote:
> > That's odd. I just tried your function with b:lico and it
> > worked fine for me: each call to LiCo() advanced the state of
> > the cursor highlights as you described. I only tried it with
> > one buffer.
>
> Yes, odd. When I run the following I get errors.
> Both terminal versions Vim 7.2.315 and Vi 6.2
>
> " toggle cursorline/cursorcolumn or center line
> highlight CursorLine NONE ctermbg=Yellow
> highlight CursorColumn NONE ctermbg=Yellow
> let b:lico=0
> function LiCo()
> let b:lico=b:lico>2 ?0 :b:lico+1
> let &cursorline=b:lico % 2
> let &cursorcolumn=b:lico / 2
> endfun
> nmap <silent> <F7> :call LiCo()<cr>
>
>
> Error detected while processing function LiCo:
> line 1:
> E121: Undefined variable: b:lico
> E15: Invalid expression: b:lico>2 ?0 :b:lico+1
> line 2:
> E121: Undefined variable: b:lico
> E15: Invalid expression: b:lico % 2
> line 3:
> E121: Undefined variable: b:lico
> E15: Invalid expression: b:lico / 2

I thought about that possibility last night. Your code initializes
b:lico only once, so for only one buffer. Here's a way to fix that
problem without using an autocommand. Change this

> let b:lico=0
> function LiCo()
> let b:lico=b:lico>2 ?0 :b:lico+1
> let &cursorline=b:lico % 2
> let &cursorcolumn=b:lico / 2
> endfun

to

function LiCo()
if !exists("b:lico")
let b:lico=0
endif
let b:lico=b:lico>2 ?0 :b:lico+1
let &cursorline=b:lico % 2
let &cursorcolumn=b:lico / 2
endfun

Untested, but I think that syntax is right.

Regards,
Gary


--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment