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.
set nocompatible " use vim defaults
set notitle " Do not override the title in xterm
set ls=2 " allways show status line
set tabstop=4 " numbers of spaces of tab character
set shiftwidth=4 " numbers of spaces to (auto)indent
set showcmd " display incomplete commands
set hlsearch " highlight searches
set ruler " show the cursor position all the time
set title " show title in console title bar
set autoindent " always set autoindenting on
set smartindent " smart indent
set cindent " cindent
set cinoptions+=g0 " don't intend access modifies in C++
set cinoptions+=L0 " Don't intend labels in C/C++
" Allow backspace anywhere in the file, not just at the start of the insert
set backspace=indent,eol,start
" smarter intendation, including proper halding of # in perl
filetype indent on
filetype plugin on
" Point to the tags file, man ctags for details
set tags=$HOME/TAGS
" Don't ask to save when leaving a buffer
set hidden
syntax on " syntax highlighing
if has("gui_running")
else
colorscheme desert
endif
" map F2 to save
map <F2> :update<CR>
imap <F2> <C-o><F2>
: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:
if has("multi_byte")
if &termencoding == ""
let &termencoding = &encoding
endif
set encoding=utf-8
setglobal fileencoding=utf-8
" Uncomment the line below if you want VIM to set BOM (Byte Order Mark) on Unicode files
" This might interfere with source code files and with other applications
"setglobal bomb
set fileencodings=ucs-bom,utf-8,latin1
endif
If you find that your default font doesn't support necessary Unicode characters, try setting it to something else:
set guifont=Courier_New:h12:cANSI
More information about vim and Unicode on Windows can be found here .