vimrc

Over the years I customized my Vim installation quite a bit. Seeing others’ vimrc files helped me a lot, so I decided to share mine as well.

Plugins that I use:


set showcmd
set number
filetype plugin on
set noswapfile
" Restore the size of the vim window
set sessionoptions+=resize
" Plugins
" ======
" clang_complete
" a.vim
" taglist
" autotag
" SingleCompile
" Pathogen
" ========
execute pathogen#infect()
" Enabled plugins:
" – jedi-vim
" – syntastic
" – LaTeX-Box
set spell
if has("gui_running")
:set guifont=DejaVu\ Sans\ Mono\ 11
:colorscheme evening
else
:colorscheme elflord
endif
if has("autocmd")
augroup module
" CakePHP *.ctp files.
" for cakePHP templates
autocmd BufRead *.ctp set filetype=php
augroup END
endif
" The next line was superseded by jedi
" autocmd FileType python setlocal tags+=$HOME/.vim/python-2.6.tags
syntax sync fromstart
" Tabs
" ====
set noexpandtab
set autoindent
filetype indent on
" I use setlocal so the tab settings will only apply for the python buffer
autocmd Filetype python setlocal tabstop=4
autocmd Filetype python setlocal expandtab
autocmd Filetype python setlocal softtabstop=4
autocmd Filetype python setlocal shiftwidth=4
autocmd Filetype python setlocal cinwords=if,elif,else,for,while,with,try,except,finally,def,class
" tab menus
:amenu Syntax.Tabs.ts=4,et,sts=4,sw=4 :set tabstop=4 expandtab softtabstop=4 shitwidth=4<CR>
:amenu Syntax.Tabs.ts=2,et,sts=2,sw=2 :set tabstop=2 expandtab softtabstop=2 shitwidth=2<CR>
" Highlight whitespace at end-of-line
autocmd Filetype python match Error /\s\+$/
" Status Line
" ===========
set statusline=%F%m%r%h%w\ [TYPE=%Y,%{eval('&fileformat')}]\ [POS=%04l,%04v][%p%%]\ [LEN=%L]
set laststatus=2 " Always display the status line.
" Searches
" ========
set incsearch " do partial searches
set hlsearch " search highlighting
set ignorecase
set smartcase
let g:netrw_retmap = 0
" TagList Plugin
" ==============
nnoremap <silent> <F8> :TlistToggle<CR>
" PyLint Plugin
" =============
"let g:pylint_onwrite = 0
"autocmd FileType python compiler pylint
" SingleCompile
" =============
nmap <F9> :SCCompile<cr>
nmap <F10> :SCCompileRun<cr>
autocmd Filetype cpp nmap <buffer> <F9> :SCCompileAF -std=c++0x <CR>
autocmd Filetype cpp nmap <buffer> <F10> :SCCompileRunAF -std=c++0x <CR>
" C++ Omnicomplete – Replaced by clang_complete
" ================
" Generating tags:
" ctags –c++-kinds=+p –fields=+iaS –extra=+q –language-force=c++
" autocmd FileType cpp set tags+=~/.vim/tags/libstdc++.tags
" autocmd FileType cpp set tags+=~/.vim/tags/wxwidgets.tags
" autocmd FileType cpp set tags+=~/.vim/tags/gtk-3.0.tags
" let OmniCpp_MayCompleteScope = 1 " autocomplete after ::
" let OmniCpp_ShowPrototypeInAbbr = 1 " show function parameters
" let OmniCpp_ShowAccess = 1
" let OmniCpp_DefaultNamespaces = ["std", "_GLIBCXX_STD"]
" clang_complete
" ==============
let g:clang_use_library = 1
" Vim Help
" ========
" search help for word under cursor
nnoremap <C-F1> :help <C-R><C-W><CR>
" Mouse
" =====
set mousemodel=popup_setpos
" makes tab/shift-tab in visual mode do what I expect from visual studio
vnoremap <Tab> >gv
vnoremap <S-Tab> <LT>gv
" Make it easier to move between window
"
" Reorder tabs
" ============
function! GuyTabLeft()
let tab_number = tabpagenr() – 1
if tab_number == 0
execute "tabm" tabpagenr('$') – 1
else
execute "tabm" tab_number – 1
endif
endfunction
function! GuyTabRight()
let tab_number = tabpagenr() – 1
let last_tab_number = tabpagenr('$') – 1
if tab_number == last_tab_number
execute "tabm" 0
else
execute "tabm" tab_number + 1
endif
endfunction
map <silent><C-S-Right> :execute GuyTabRight()<CR>
map <silent><C-S-Left> :execute GuyTabLeft()<CR>
" CScope
" ======
set cscopetag
set cscopetagorder=0 " Use cscope before tag file
if filereadable("cscope.out")
cscope add cscope.out
endif
nnoremap <A-]>s :cs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <A-]>g :cs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <A-]>c :cs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <A-]>t :cs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <A-]>e :cs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <A-]>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap <A-]>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap <A-]>d :cs find d <C-R>=expand("<cword>")<CR><CR>
" Using 'CTRL-spacebar' then a search type makes the vim window
" split horizontally, with search result displayed in
" the new window.
nnoremap <C-Space>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap <C-Space>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap <C-Space>d :scs find d <C-R>=expand("<cword>")<CR><CR>
" Hitting CTRL-space *twice* before the search type does a vertical
" split instead of a horizontal one
nnoremap <C-Space><C-Space>s
\:vert scs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space><C-Space>g
\:vert scs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space><C-Space>c
\:vert scs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space><C-Space>t
\:vert scs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space><C-Space>e
\:vert scs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-Space><C-Space>i
\:vert scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
nnoremap <C-Space><C-Space>d
\:vert scs find d <C-R>=expand("<cword>")<CR><CR>
" Misc
" ====
" join lines in reverse order
nnoremap <C-j> ddpkJ
nnoremap + :vim/\C\<<C-R><C-w>\>/ **/*.%:e<CR>
nnoremap <C-S> :tab split<CR>
nnoremap <C-S-Tab> :tabprevious<CR>
nnoremap <C-Tab> :tabnext<CR>
" Fast exit from Insert Mode
inoremap kj <ESC>
" Properly display man pages
" ==========================
runtime ftplugin/man.vim
if has("gui_running")
nnoremap K :<C-U>exe "Man" v:count "<C-R><C-W>"<CR>
endif
" Textwidth settings
" ==================
autocmd Filetype tex set textwidth=72

view raw

vimrc

hosted with ❤ by GitHub

Last update: 07/12/2013

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.