vi、设置用户设置

vi, set user settings

在使用 vi 时,我几乎总是需要做

:set hlsearch
:set number

如何让我的系统在使用 vi 时始终将这些作为预设或其他内容加载。

在一台机器上我是 root,在另一台机器上不是。因此,请包括两者的答案。谢谢!

您可以在您的主目录中创建一个名为 .exrc 的文件,并在其中写入所有命令(不带前面的 : )。

When you start the vi editor, the editor searches for the environment variable $EXINIT and uses the contents of the file it points to as configuration commands, if it exists. If EXINIT is not defined, vi looks for the .exrc file in your HOME directory, and uses its configuration commands. Finally, vi looks in your current directory for a file named .exrc and executes the commands in that file, if it exists. In this manner, you can have a different vi configuration for each directory or project that you're working on. (http://alvinalexander.com/unix/edu/un010003/)

vim对应的文件名为.vimrc.

只需创建一个包含以下条目的 .vimrc 文件:

set hlsearch
set number

将此文件放在您在特定计算机上使用的用户的 $HOME 目录中:

/root/在您所在的机器上 root
/home/USERNAME在您的用户所在的计算机上 USERNAME

如果 .vimrc 不存在,请创建它。