3

We would like to be able to start vi (or vim) up with an alternative ex initialisation file. By default this is ~/.exrc.

Unfortunately vim(1), which is also brought up for "man ex" on this system, doesn't mention .exrc.

Any workarounds to provide equivalent behaviour would also be appreciated.

projix
  • 211
  • 1
  • 4

3 Answers3

2

I was expecting the common -u conf_file to work, but that fails here. A workaround is to load no configuration file with -u NONE and then source the one you want with -c:

ex -u NONE -c 'source your_local_exrc'
Thor
  • 45,082
  • 11
  • 119
  • 130
  • 1
    Thanks Thor. That was enough info to find what I was after, which is "vi -u NONE -S your_local_exrc". Because -c is for commands, whereas -S sources the file. I also now see that detailed documentation for this is available by running ":help init" from within vim. My initial search for exrc within the man page wasn't sufficient. – projix Jul 17 '12 at 19:56
  • I meant to say `-c 'source your_local_exrc'` (fixed it now), but `-S` is even better :). – Thor Jul 17 '12 at 20:04
1

Some versions of traditional vi/ex use the EXINIT environment variable as a command string to execute on startup, and execute $HOME/.exrc if it is not set. If you're running such a version, you can set EXINIT to so /other/file/to/execute to source an alternate startup file.

evil otto
  • 10,348
  • 25
  • 38
  • Thanks. Now that I've found ":help init" from within vim, I see that the EXINIT environment variable, and its precedence over ~/.exrc, is indeed documented there. – projix Jul 17 '12 at 19:59
1

In your ~/.exrc (for vi) file add following lines at start

set exrc   " Dangerous
set secure " Disables shell and write commands in .exrc/.vimrc

This will make sure that the .exrc file from the current directory will be loaded if it exists.

oxr463
  • 1,573
  • 3
  • 14
  • 34
prashant
  • 1,144
  • 9
  • 15