Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vi, set user settings

Tags:

linux

vi

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!

like image 333
thahgr Avatar asked Dec 04 '22 04:12

thahgr


2 Answers

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.

like image 92
Sebastian Stigler Avatar answered Dec 16 '22 18:12

Sebastian Stigler


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.

like image 27
davir Avatar answered Dec 16 '22 17:12

davir