How to Create a Global Vim Configuration for All Users (/etc/vimrc)


2 views

Managing Vim configurations across multiple users can be tedious. While having per-user ~/.vimrc files provides customization flexibility, it creates maintenance overhead when you want to enforce certain default settings for all users.

Vim actually looks for configuration files in several locations with this precedence order:

1. ~/.vimrc (user-specific)
2. /etc/vimrc (system-wide)
3. $VIM/vimrc (fallback)

To create global defaults, we should use /etc/vimrc which affects all users while still allowing individual overrides.

First, check if /etc/vimrc already exists:

ls -l /etc/vimrc

If not, create it with your preferred settings:

sudo touch /etc/vimrc
sudo chmod 644 /etc/vimrc

Here's a sample /etc/vimrc with common defaults:

" Set UTF-8 encoding
set encoding=utf-8

" Basic editor settings
set number
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent

" Security defaults
set modelines=0
set nomodeline

" Visual improvements
syntax on
set background=dark
set cursorline

" Allow user overrides
if filereadable(expand("~/.vimrc"))
    source ~/.vimrc
endif

When implementing a global config:

  • Keep it minimal - only include truly universal settings
  • Document the existence of system-wide defaults
  • Allow user customization via ~/.vimrc
  • Test changes thoroughly before deployment

To test your global settings:

sudo -u nobody vim -N -u NONE -U NONE -i NONE

This runs Vim as a generic user without loading any personal configs.


While individual ~/.vimrc files work well for personal customization, system administrators often need to enforce consistent Vim settings across multiple users. This is particularly useful in:

  • Development teams requiring standardized editor configurations
  • University computer labs
  • Server environments where multiple users need similar setups

Vim loads configuration files in this order:

1. /etc/vimrc (system-wide)
2. ~/.vimrc (user-specific)
3. ~/.vim/vimrc (alternative user location)
4. Settings from $VIMINIT environment variable

On most Linux systems, you can create or modify the global Vim configuration at:

sudo vim /etc/vimrc

For macOS (Homebrew installation):

sudo vim /usr/local/share/vim/vimrc

Here's a practical example of what you might include:

" Set basic defaults
set nocompatible
set backspace=indent,eol,start
set history=1000
set ruler
set showcmd
set incsearch

" Standard indentation
set tabstop=4
set shiftwidth=4
set expandtab

" Enable syntax highlighting
syntax on

" Security settings
set modelines=0
set nomodeline

" Recommended for multi-user systems
set secure

The global configuration will be loaded before user-specific ~/.vimrc files, so users can still override settings. To prevent certain overrides, use:

" In /etc/vimrc
if !exists("g:loaded_restricted_mode")
    let g:loaded_restricted_mode = 1
    set nomodifiable
    " Other protected settings...
endif

Verify the global settings work by creating a test user:

sudo useradd vimtest
sudo -u vimtest vim

Check that your defaults are applied without a ~/.vimrc file present.

For systems where you want new users to start with a default .vimrc (but allow complete modification), place it in:

/etc/skel/.vimrc

This file will be copied to new users' home directories during account creation.

  • Document all global settings in a header comment
  • Avoid personal preferences in the global config
  • Include only security-conscious settings
  • Test with various user permission levels
  • Consider version controlling your /etc/vimrc