Sample .vimrc file for software developers

Vim is a very powerful and convenient text editor for Unix environments. I certainly don't wish to start any disputes along the lines of the old vim/emacs frontier, especially since I used both of them for long periods of time and find unique features in each. However in recent years I tend to use vim most of the time, mainly because it is quite lightweight. In order to benefit the most from the editor it needs to be configured to suit my specific requirements. Due to nature of my work, that is working as a consultant for different clients, I occasionally find myself recreating my ~/.vimrc configuration file at a new workstation or remote server. Since time spans between these activities are often quite considerable, I forget everything there is to know about the syntax and the inner quirks of this wonderful beast. So in order to save some precious time in the future, I'll put a sample in my blog, thus helping myself and, hopefully, the public as well. Many of the settings are geared towards software developers.

  1. set nocompatible    " use vim defaults
  2. set notitle    " Do not override the title in xterm
  3. set ls=2            " allways show status line
  4. set tabstop=4       " numbers of spaces of tab character
  5. set shiftwidth=4    " numbers of spaces to (auto)indent
  6. set showcmd         " display incomplete commands
  7. set hlsearch        " highlight searches
  8. set ruler           " show the cursor position all the time
  9. set title           " show title in console title bar
  10. set autoindent     " always set autoindenting on
  11. set smartindent        " smart indent
  12. set cindent            " cindent
  13. set cinoptions+=g0  " don't intend access modifies in C++
  14. set cinoptions+=L0  " Don't intend labels in C/C++
  15. " Allow backspace anywhere in the file, not just at the start of the insert
  16. set backspace=indent,eol,start
  17. " smarter intendation, including proper halding of # in perl
  18. filetype indent on
  19. filetype plugin on
  20. " Point to the tags file, man ctags for details
  21. set tags=$HOME/TAGS
  22. " Don't ask to save when leaving a buffer
  23. set hidden
  24. syntax on           " syntax highlighing
  25.  
  26. if has("gui_running")
  27. else
  28.     colorscheme desert
  29. endif
  30.  
  31. " map F2 to save
  32. map <F2> :update<CR>
  33. imap <F2> <C-o><F2>
  34. :noremap <silent> <c-l> :nohls<cr><c-l>

If you are using vim on Windows and want to be able to edit Unicode files with ease, consider adding the following piece of configuration:

  1. if has("multi_byte")
  2.   if &termencoding == ""
  3.     let &termencoding = &encoding
  4.   endif
  5.   set encoding=utf-8
  6.   setglobal fileencoding=utf-8
  7.   " Uncomment the line below if you want VIM to set BOM (Byte Order Mark) on Unicode files
  8.   " This might interfere with source code files and with other applications
  9.   "setglobal bomb
  10.   set fileencodings=ucs-bom,utf-8,latin1
  11. endif

If you find that your default font doesn't support necessary Unicode characters, try setting it to something else:

  1. set guifont=Courier_New:h12:cANSI

More information about vim and Unicode on Windows can be found here.

Add new comment