On Tuesday 19 August 2008 09:50, Charles Campbell wrote:
>
> sc wrote:
> > thank *you* -- it looks really useful
> >
> > now can you help me make a toggle for it, so i don't need to
> > burn two mappings for it? like for example instead of
> > saying "RltvNmbr is already enabled", which i can plainly
> > see, why not turn it off?
> >
> > i looked for a variable i could test for in a toggle
> > function but nothing jumped out at me
> >
> RltvNmbr! will turn it off.
>
> You could write your own command and function to do the toggling; as an
> example,
>
> com! RN call s:RN()
> fun! s:RN()
> if !exists("s:RN")
> let s:RN=1
> else
> let s:RN= !s:RN
> endif
> if s:RN
> RltvNmbr
> else
> RltvNmbr!
> endif
> endfun
>
> Then :RN will toggle RltvNmbr.
>
> Regards,
> Chip Campbell
because we're using exists(), turning it off with !s:RN only
works once -- here's my implementation:
nnoremap <silent> <Leader>rrr :silent call ToggleRltvNmbr()<CR>
function! ToggleRltvNmbr()
if !exists("s:RN")
let s:RN = 1
RltvNmbr
else
unlet s:RN
RltvNmbr!
endif
endfunction
and i used my spiffy new relative numbers to yank the
function for pasting here -- i love it!
i may make RN buffer local, so i can use this in other
buffers in the same edit session without having to hit the
toggle three times, but already this is wonderful
thanx again charles
sc
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---