Home > Bash, Vim, open source, platforms and frameworks, sysadmin > Global (all users) vim configuration, i.e. enabling autocomplete and syntax highlighting

Global (all users) vim configuration, i.e. enabling autocomplete and syntax highlighting

August 29th, 2008

In Linux, the global vim configuration is generally in /etc/vim/. For instance, while you might want to configure some options for yourself in ~/.vimrc, global options that you wish to apply for all users go into /etc/vim/vimrc (no ‘dot’). Your vim installation directory, something like /usr/share/vim/vim70/ has folders autoload/, syntax/, and plugin/, but altering these is not a good idea, since you could lose your modifications when vim is upgraded. Creating the same directories under /etc/vim/ is safer and more correct. /etc/vim/autoload/* will execute automatically, just like the autoload scripts in the installation dirs and the autoload scripts under ~/.vim/autoload/.

Below is the /etc/vim/vimrc file as it exists on two of our development servers. Please consult the vim documentation or :help for full explanation of any of these directives. In bold are the directives for syntax highlighting and autocomplete:

set nocompatible
set autoindent
set smartindent
set ruler
set incsearch
set tabstop=4
set shiftwidth=4
syntax on
color elflord
set backspace=indent,eol,start

"PDV vim plugin - ctrl-P on any line 
"will document that line outamatically in PHPdoc syntax
au FileType php source /etc/vim/plugin/php-doc.vim
au FileType php inoremap <C-P> <ESC>:call PhpDocSingle()<CR>i
au FileType php nnoremap <C-P> :call PhpDocSingle()<CR>
au FileType php vnoremap <C-P> :call PhpDocRange()<CR>

"Enable autocomplete via ctrl-x ctrl-o
setlocal omnifunc=syntaxcomplete#Complete
" Javascript didnt seem to register correctly with the setlocal 
" command above
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
" Make it a little easier to autocomplete (ctrl-J instead of ctrl-X, ctrl-O)
" Ctrl-J is the same as the enter key by default, so it's harmless to remap 
" it to the autocomplete command sequence to make it home-row friendly. 
inoremap <C-J> <C-X><C-O>
social bookmark of choice:
  • Digg
  • del.icio.us
  • Ma.gnolia
  • Reddit
  • Slashdot

Greg Bash, Vim, open source, platforms and frameworks, sysadmin ,

  1. No comments yet.