5

I would like to set up system-wide vi settings.

I know i can setup preferences for vim editor in /etc/vimrc and ~/.vimrc

but I don't think my vi on CentOS7 is reading anything from the vimrc files or locations such as /etc/virc or ~/.virc

vincentleest
  • 163
  • 1
  • 1
  • 7
  • Try find /etc -name vimrc – Costas Jan 23 '15 at 20:18
  • While this is for Ubuntu (Debian) rather than CentOS (RedHat) http://askubuntu.com/questions/60041/why-isnt-vim-reading-my-global-configuration-file - the information may be useful. – sonnik Jan 23 '15 at 20:35
  • You can use any file you want that you source in $EXINIT. ~/.exrc and $EXINIT are always ignored when calling vi/ex/open on a file named - though. – mikeserv Jan 23 '15 at 21:04

2 Answers2

7

Poking at POSIX:

Initialization in ex and vi
   See  Initialization  in  ex  and  vi  for  a  description  of ex and vi
   initialization for the vi utility.

And the manpage for ex says:

   IEEE Std 1003.1-2001  does  not  mention system-wide ex and vi start-up
   files. While they exist in several implementations of ex and  vi,  they
   are  not  present in any implementations considered historical practice
   by IEEE Std 1003.1-2001.  Implementations that have such  files  should
   use  them  only if they are owned by the real user ID or an appropriate
   user (for example, root on UNIX systems) and if they are  not  writable
   by  any  user other than their owner. System-wide start-up files should
   be read before the EXINIT variable, $HOME/.exrc, or local  .exrc  files
   are evaluated.

So I suppose /etc/exrc is your best bet for old-school vi.

However, vi on CentOS 7 is likely just vim-minimal, in which case the startup files will still be using vim in their name: /etc/vimrc or /etc/vim/vimrc.

muru
  • 72,889
3

The question is specifically about CentOS7, and mentions vim. That can only be one of a few packages: vim-minimal, vim-enhanced, vim-x11. CentOS does not provide packages for other implementations of vi, such as nvi.

The package description for vim-minimal says

The vim-minimal package includes a minimal version of VIM, which is installed into /bin/vi for use when only the root partition is present.

and man vi gives the vim manpage, which lists the system configuration files used:

   /etc/vimrc     System wide Vim initializations.
   /etc/gvimrc    System wide gvim initializations.

and since there is no mention of gvim, the proper answer is /etc/vimrc.

Note that vim's documentation does not list a different configuration file when running as vi. There are no /etc/virc or ~/.virc files.

Actually, POSIX avoids telling where any system configuration files might reside. Keith Bostic (who wrote most of the POSIX description of vi) used a different system configuration file for nvi:

   /etc/vi.exrc

Besides not mentioning system configuration files, Bostic also chose not to document modelines (or implement them in nvi). The two are related. Other implementations of vi provide (optionally or not) a way to read a configuration file from the current directory. That can lead to unexpected results, and modelines can aggravate that. The Unix systems (AIX, HPUX, Solaris) make these features optional (as do elvis, and vim), based on the settings exrc and modeline. nvi also uses the exrc setting for the same purpose.

vim's manpage does not mention, but the help/documentation does say that if it cannot find a suitable ~/.vimrc, it will look for /.exrc (no /etc/exrc). The ~/.exrc was documented for SunOS 4. Solaris 10 likewise mentions ~/.exrc, but not /etc/exrc.

Further reading:

Thomas Dickey
  • 76,765