6

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!

1
  • (hlsearch is for vim). When you are root, you might be changing things your colleagues don't like. Are you using a terminal emulator / ssh client where you can define key-sequences? Than you might put your favorite lines under a special key-combination.
    – Walter A
    Commented Feb 3, 2015 at 13:14

2 Answers 2

13

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.

8
  • 4
    This is valid for vim, not vi
    – davir
    Commented Feb 3, 2015 at 13:04
  • 2
    On most systems vi and vim are symlinks to the same binary Commented Feb 3, 2015 at 13:07
  • @davir Then install vim first, vim is the most basic tool.
    – Eric
    Commented Feb 3, 2015 at 13:08
  • 2
    OP asked about vi, not vim.
    – davir
    Commented Feb 3, 2015 at 13:09
  • in my directory I have only .viminfo . Not .vimrc. I dont know if it will work for vi or vim or both, i will try and tell you
    – thahgr
    Commented Feb 3, 2015 at 13:20
8

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.