I wanted a function key to turn on and off the highlighting, but did
not want to dedicate more than one of those valuable resources. So...
in this example F7 cycles thru the cursorline and cursorcolumn
highlighting.
For Vim versions older that 7, it only moves the line to the center of
the screen.
I am somewhat new to Vim scripting, please comment or suggest
improvements.
" toggle cursorline/cursorcolumn or center line
nmap <F7> zz
if version >= 700 " NONE turns off underlining
highlight CursorLine NONE ctermbg=Yellow
highlight CursorColumn NONE ctermbg=Yellow
let s:lico=0
function LiCo()
let s:lico=s:lico>2 ?0 :s:lico+1
let &cursorline=s:lico % 2
let &cursorcolumn=s:lico / 2
endfun
nmap <silent> <F7> :call LiCo()<cr>
endif
imap <F7> <c-o><F7>
vmap <F7> <c-c><F7>gv
You might be interested in
:set {option}!
:set inv{option}
either of which will toggle the value of {option}. See
:help E518
and skip to the fourth paragraph down.
Regards,
Gary
I know about them, but did not know the 'reset'.
:se[t] {option}&
I had been using:
:nmap <silent> <F7> :set cursorline!<cr>
:nmap <silent> ,<F7> :set cursorcolumn!<cr>
But decided that I wanted to cycle 1-4 with ONE key
and to learn something new:
1) off
2) cursorline
3) cursorcolumn
4) both cursorline and cursorcolumn
How can LiCo() be made buffer local?
let s:lico=0
function LiCo()
let s:lico=s:lico>2 ?0 :s:lico+1
let &cursorline=s:lico % 2
let &cursorcolumn=s:lico / 2
endfun
I tried b:lico in place of s:lico, it did not work.
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.
Regards,
Gary
This mail does not poertains to me. Please mark the same to right
person.
Thanks and Regards
Om Prakash Singh | Asst. Manager |Kotak Mahindra Bank Ltd.
5/27, Vishal Khand, Gomtinagar, Lucknow 226010 | D: (0522) 4151910 | M:
(+91) 9936250828
Regards,
Gary
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
DISCLAIMER:
This communication is confidential and privileged and is directed to and for the use of the addressee only. The recipient if not the addressee should not use this message if erroneously received, and access and use of this e-mail in any manner by anyone other than the addressee is unauthorized. The recipient acknowledges that Kotak Mahindra Bank may be unable to exercise control or ensure or guarantee the integrity of the text of the email message and the text is not warranted as to completeness and accuracy. Before opening and accessing the attachment, if any, please check and scan for virus.
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
--
Bill
Santa Cruz, California
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
Thank you, that works and is a very good to know.