How can I set gvim's window width to 80 columns of text, plus the ones needed to show the line number

Try this in your ~/.vimrc:

au BufRead * let &numberwidth = float2nr(log10(line("$"))) + 2
          \| let &columns = &numberwidth + 80

Every time you load a buffer (i.e., open a file), that will determine the number of columns required to show the largest line number, set the 'numberwidth' option accordingly, and set 'columns' to that number plus 80 for your text.


I set the numberwidth to, say, 5 and then set the columns to 85 (80+5) That should be good for files from 0 lines to a million lines.

Here is what you may have to put in (default) ~/.vimrc file

set numberwidth=5  "Good for files upto a million lines
set columns=85
set nu

You will see line number are formatted with '%5d' (5 is the numberwidth above) instead of default '%d' format, wasting a bit of real-estate before the line numbers, but maintaining consistency.


I use

set lines=24 columns=84

in my $HOME/.gvimrc which gives me what you want. I rarely (if ever) have files that are longer the 999 lines so it works for me.

Tags:

Vim

Gvim