Friday, October 28, 2011

Turning on the right line numbering when needed

On Oct 28, 1:51 pm, AK <andrei....@gmail.com> wrote:
> On 10/28/2011 02:43 PM, George V. Reilly wrote:
>
>
>
> > You know what'd really make a difference for relative line numbering?
> > If the current line's number was its absolute line number, instead of
> > "0". Yes, I can see the absolute line number down in the ruler, but
> > that's often far removed from the current line and I have to move my
> > eyes down to the ruler, then back to the current line. "0" conveys
> > little information. The absolute line number is more useful. It should
> > be in a highlighted color to make it blatantly clear that it's
> > different.
>
> I have to disagree, at least for me, absolute line number is not
> something I need that often. Absolute line number would need an
> extra column or two. I have relative line numbers column set to
> 3 - 2 digits and one column of padding (which looks like it's not
> possible to remove?)
>

I don't need it that often either, but I had a sudden realization one
day, that pretty much the only times I DO need them, is when I'm
referring to code open in Vim while writing emails, problem reports,
and the like. So I put this gem in my .vimrc to automatically give me
absolute numbers only when I need them most often: when Vim doesn't
have focus.

if exists('+relativenumber')
" when Vim no longer has focus, relative line numbers are not
useful,
" although absolute numbers are
autocmd FocusLost * let s:FL_winnr = winnr() |
\ exec 'windo
\ if &ft !~ "txt" && &buftype=="" |
\ let w:nu_sav = &nu | let w:rnu_sav = &rnu | setl nu
|
\ endif' |
\ exec s:FL_winnr.'wincmd w' | unlet s:FL_winnr
autocmd FocusGained * let s:FL_winnr = winnr() |
\ exec 'windo if exists("w:nu_sav") |
\ let &l:nu = w:nu_sav |
\ unlet w:nu_sav |
\ endif |
\ if exists("w:rnu_sav") |
\ let &l:rnu = w:rnu_sav |
\ unlet w:rnu_sav |
\ endif' |
\ exec s:FL_winnr.'wincmd w' | unlet s:FL_winnr
endif

Incidentally, it was an earlier version of this which led to my
discovery that system() calls on Windows get FocusGained, but not
FocusLost. But that's even further off-topic than this discussion of
relative line numbering.

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

No comments:

Post a Comment