vim settings

Submitted by sean on Mon, 01/11/2010 - 11:40

As a vi user for a long, long time, I've got used to only using the basic features - since many unix systems have a basic vi installed.

Vim configuration

Recently most of the systems I manage have moved from Solaris to Ubuntu so the nicer features in VIM can be taken advantage of. This page is a brief summary where I'll keep track of interesting settings. Some Ubuntu versions only have a basic vi, so do a "apt-get install vim" first.

Features to enable in standard Ubuntu /etc/vim/vimrc

syntax on
set background=dark                          (if reverse video is used to access that server)
if has("autocmd")
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal g'\"" | endif
if has("autocmd")
  filetype indent on
set showcmd   " Show (partial) command in status line.
set showmatch   " Show matching brackets.

More sugar, especially for PHP editing.

set hlsearch
set tabstop=2
set showcmd
set incsearch
autocmd FileType php let php_sql_query=1
autocmd FileType php let php_htmlInStrings=1
autocmd FileType php let php_noShortTags=1
autocmd FileType php DoMatchParen
autocmd FileType php hi MatchParen ctermbg=blue guibg=lightbl
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType php set omnifunc=phpcomplete#CompletePHP
autocmd FileType c set omnifunc=ccomplete#Complete

See also

Usage tips

The following are features that don't use, but note them because they are interested and need to start on them.


    *  To open multiple files in tabs from the command line.
      vim -p filename1 filename2
    * To open and jump to the end of a file
      vi +filename1

    * :tabnew to open a new tab.
    * gt to switch to the next tab.
    * gT to switch to the previous tab.
    * :tabc to close a tab.

    * :split or Ctrl-w s will split the Vim view into two viewports, horizontally.
    * :vsplit or Ctrl-w v will split the Vim view into two viewports, vertically.
    * :split filename will split the Vim view into two viewports, horizontally, and open filename in the new viewport.
    * :vsplit filename will split the Vim view into two viewports, vertically, and open filename in the new viewport.
    * Ctrl-w r moves viewports clockwise.
    * Ctrl-w R moves viewports counter-clockwise.

Scratching the surface

There is so much more to learn about vi..…