On Thu, Nov 6, 2014 at 5:02 PM, Ben Fritz <[email protected]> wrote:

> On Thursday, November 6, 2014 2:53:02 PM UTC-6, Salman Halim wrote:
> > Hi,
> >
> > I was wondering if it was possible to switch to relative line numbers
> once I'm in operator-pending mode and then switch back when done. For
> example, say I have regular line numbers turned on and I hit 'c' in normal
> mode on line 24. The numbering changes to relative and goes back to regular
> numbers after the rest of the command is executed.
> >
> > I couldn't find an autocommand, but was hoping someone else had already
> come up with an ingenious way to address this.
> >
>
> I did not find any autocmd for it, but I use an expression mapping
> returning an empty string in normal, visual, and operator-pending modes to
> accomplish the task:
>
> if exists('+relativenumber')
>   nnoremap <expr> <C-Space> CycleLNum()
>   xnoremap <expr> <C-Space> CycleLNum()
>   onoremap <expr> <C-Space> CycleLNum()
>
>   " function to cycle between normal, relative, and no line numbering
>   func! CycleLNum()
>     if &l:rnu && !&l:nu
>       setlocal nu
>     elseif &l:rnu && &l:nu
>       setlocal nornu
>     elseif &l:nu && !&l:rnu
>       setlocal nonu
>     else
>       setlocal rnu
>     endif
>     " sometimes (like in op-pending mode) the redraw doesn't happen
>     " automatically
>     redraw
>     " do nothing, even in op-pending mode
>     return ""
>   endfunc
> endif
>
> Thus when I hit <C-Space> in any of these modes, nothing happens, which
> allows me to continue with my operation, but the line numbering changes as
> a side effect.
>
>
Ben, thank you very much for this; in the absence of an autocommand, this
the perfect alternative.

Much appreciated!

Salman

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

--- 
You received this message because you are subscribed to the Google Groups 
"vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to