删除 vi 编辑器中由“set nu”选项创建的空白

删除 vi 编辑器中由“set nu”选项创建的空白

我在许多不同的机器上多次使用过 vi 编辑器,但从未见过这样的set nu选项行为。

这是我在主目录中的文件 set nu中设置选项后 vi 编辑器的样子:.vimrcvi 编辑器屏幕截图

显然,行号左侧出现了一些空白。如何删除这些空白,以便更好地利用工作空间?

提前致谢。

答案1

来自帮助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.

反过来,来自: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.

也就是说,默认宽度为 4,但在compatible模式下为 8。viUbuntu 默认是vim.tiny,不支持nocompatible,所以宽度变成了8。您需要安装vim才能获得正常行为。

也就是说,如果您确实希望设置不同的最小宽度,比如 2,只需执行以下操作:

set nuw=2

相关内容