My .vimrc

By the time you have worked enough with vim to require you save your preferences in the ~/.vimrc, you probably know what you’re going to put there. So I don’t expect this to be useful to anyone except myself. But, hey, I am a person, too.

I have a buffer plugin to help keeping track of the files I’m editing, vim tab-completion is amazing and I use it a lot, I also use cscope and GNU Global to inspect the code, and I build right from the editor.

" Match angle brackets (need this for templates)
set mps+=<:>
" Auto-save before :make
set autowrite
" Hide abandon buffers in order not to loose undo history when switching buffers
set hid

" Don't wrap long lines (this better be content-dependent, see below)
set nowrap

set nocompatible
set history=50          " keep 50 lines of command line history
set ruler               " show the cursor position all the time
set showcmd             " display incomplete commands
set mouse=a             " mouse on
set hlsearch		" highlight last search
syntax on		" syntax highlighting
set encoding=koi8-r
set termencoding=koi8-r

colorscheme desert

set colorcolumn=80	" draw a red line at 80 column

" MiniBufExplorer options
let g:miniBufExplVSplit = 20 " vertical buffers list
let g:miniBufExplBRSplit = 0 " put it to the right

" Only do this part when compiled with support for autocommands.
if has("autocmd")
  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78
  " The text is meant to be read and doesn't always has linebreaks inside
  " paragraphs, so it's better to wrap it
  autocmd FileType text setlocal wrap

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  autocmd BufReadPost *
    \ if line("'\"") > 0 && line("'\"") <= line("$") |
    \   exe "normal g`\"" |
    \ endif

  augroup END
else
  set autoindent                " always set autoindenting on
endif " has("autocmd")

" Nice formatting
set softtabstop=4
set shiftwidth=4

" I used to use cscope to jump to a declaration/definition; now I prefer gtags
if has("cscope")
    set csprg=cscope
    set csto=0
    set cst
    set nocsverb
    " add any database in current directory
    if filereadable("cscope.out")
	cs add cscope.out
	" else add database pointed to by environment
    elseif $CSCOPE_DB != ""
	cs add $CSCOPE_DB
    endif
    set csverb
endif

"Use TAB to complete when typing words, else inserts TABs as usual.
"Uses dictionary and source files to find matching words to complete.

"See help completion for source,
"Note: usual completion is on <C-n> but more trouble to press all the time.
"Never type the same word twice and maybe learn a new spellings!
"Use the Linux dictionary when spelling is in doubt.
"Window users can copy the file to their machine.
function! Tab_Or_Complete()
  if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
    return "\<C-N>"
  else
    return "\<Tab>"
  endif
endfunction
:inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>

" work-specific
" what to execute on the :make command
set makeprg=cd\ build-dir\ &&\ dmake\ -j\ 6\ something
" where to look for files (kinda like -I for the compiler)
set path=...

Oh, and I find these plugins very helpful:

Maxim Kartashev

Maxim Kartashev
Pragmatic, software engineer. Working for Altium Tasking on compilers and tools for embedded systems.