1

I have used vi editor several times on many different machines, but I have never seen such an behavior of set nu option.

This is what my vi editor looks after I set the set nu option in .vimrc file in my home directory: vi editor screen-shot

As clearly seen, some amount of whitespace is being created to the left of line numbers. How can I remove this space so that I can better make use of my workspace.

Thanks in advance.

6
  • Are you running it as vi or vim? Did you test after adding nocompatible? The docs say: 'numberwidth' is reset to 8 when 'compatible' is set.
    – muru
    Oct 24, 2015 at 6:54
  • @muru I am running it as vi. Yes, I have tested it after adding set nocompatible option, as already shown in the screenshot.
    – Swaroop
    Oct 24, 2015 at 6:57
  • Run it as vim. No, your screenshot doesn't tell me that - for all I know you could have added it, and then taken the screenshot.
    – muru
    Oct 24, 2015 at 6:58
  • @muru Yeah! As this is a new installation of Ubuntu, when I tried to open with vim, I realized that vim is not installed, so after installation of vim it works, with both vi as well as vim. But, what was the editor which got opened when I tried to previously open with vi ?
    – Swaroop
    Oct 24, 2015 at 7:03
  • its vim.tiny a barebones version of Vim: askubuntu.com/a/434632/158442'
    – muru
    Oct 24, 2015 at 7:04

1 Answer 1

0

From the help on nu (:h 'number')

                                'number' 'nu' 'nonumber' 'nonu'
'number' 'nu'           boolean (default off)
                            local to window
        Print the line number in front of each line.  When the 'n' option is
        excluded from 'cpoptions' a wrapped line will not use the column of
        line numbers (this is the default when 'compatible' isn't set).
        The 'numberwidth' option can be used to set the room used for the line
        number.

And in turn, from :h 'numberwidth':

'numberwidth' 'nuw'     number  (Vim default: 4  Vi default: 8)
                        local to window
                        {not in Vi}
                        {only available when compiled with the +linebreak
                        feature}
        Minimal number of columns to use for the line number.  Only relevant
        when the 'number' or 'relativenumber' option is set or printing lines
        with a line number. Since one space is always between the number and
        the text, there is one less character for the number itself.
        The value is the minimum width.  A bigger width is used when needed to
        fit the highest line number in the buffer respectively the number of
        rows in the window, depending on whether 'number' or 'relativenumber'
        is set. Thus with the Vim default of 4 there is room for a line number
        up to 999. When the buffer has 1000 lines five columns will be used.
        The minimum value is 1, the maximum value is 10.
        NOTE: 'numberwidth' is reset to 8 when 'compatible' is set.

That is, the default width is 4, but 8 when in compatible mode. vi in default Ubuntu is vim.tiny, which doesn't support nocompatible, so the width became 8. You need to install vim to get the normal behaviour.

That said, if you do wish to set a different minimum width, say 2, just do:

set nuw=2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .