vim行号 - 默认情况下如何启用它们?

问题描述 投票:252回答:7

我可以从我正在编辑的文件中找到:set number但是如何让它们始终默认打开?

vim vi editing line-numbers
7个回答
399
投票

set number添加到主目录中的.vimrc文件中。 如果.vimrc文件不在您的主目录中,请使用vim .vimrc创建一个文件并在打开时添加所需的命令。

Here's a site解释了vimrc以及如何使用它。


63
投票

要更改默认设置以在vi / vim中显示行号:

vi ~/.vimrc

然后将以下行添加到文件中:

set number

我们可以source ~/.vimrc或保存并退出:wq,现在vim会话将有编号:)


10
投票

终点站> su> password> vim /etc/vimrc

单击此处并按行号(13)进行编辑:

set nu


7
投票

我的主目录中没有.vimrc文件。我创建了一个,添加了这一行:

set number

这解决了这个问题。


2
投票

在主目录中,您将在该文件中找到一个名为“.vimrc”的文件,添加此代码“set nu”并保存并退出并打开新的vi文件,您将在其上找到行号。


2
投票

我正在使用Debian 7 64位。

我的主文件夹中没有.vimrc文件。我创建了一个,并能够为vim设置用户默认值。

但是,对于Debian 7,另一种方法是编辑/ etc / vim / vimrc

这是该文件中的注释块:

" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.

1
投票

如果您不想添加/编辑.vimrc,则可以从

vi "+set number" /path/to/file
© www.soinside.com 2019 - 2024. All rights reserved.