thahgr
thahgr

Reputation: 795

vi, set user settings

When using vi I almost always need to do

:set hlsearch
:set number

How can I make my system always load these as presets or something when I use vi.

In one machine I am root, in another not. So please include an answer for both. Thank you!

Upvotes: 6

Views: 14622

Answers (2)

Sebastian Stigler
Sebastian Stigler

Reputation: 7289

just create a .vimrc file with the following entries:

set hlsearch
set number

Put this file in the $HOME directory of the user you are using on the particular machine:

/root/on the machine where you are root.
/home/USERNAMEon the machine where your user is USERNAME

if .vimrc does not exist, create it.

Upvotes: 13

davir
davir

Reputation: 942

You can create a file named .exrc in your home directory and write all the commands (without the preceding : ) there.

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/)

The corresponding file for vim is called .vimrc.

Upvotes: 8

Related Questions