vimrc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. "
  2. " Vim configuration file (~/.vimrc)
  3. " 2009, kolter <kolter@openics.org>
  4. "
  5. " This file is distributed in the hope that it will be useful,
  6. " but WITHOUT ANY WARRANTY
  7. "
  8. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  9. " General Settings
  10. "
  11. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  12. "Term settings (under tmux)
  13. if &term =~ '^screen'
  14. "tmux will send xterm-style keys when its xterm-keys option is on
  15. execute "set <xUp>=\e[1;*A"
  16. execute "set <xDown>=\e[1;*B"
  17. execute "set <xRight>=\e[1;*C"
  18. execute "set <xLeft>=\e[1;*D"
  19. endif
  20. set nocompatible "no vi compatibility
  21. set history=200 "command history size
  22. set undolevels=120 "undo levels count
  23. set autoread "notify file changes
  24. set autochdir "switch to the current file directory
  25. set clipboard+=unnamed "share system clipboard
  26. set backup "enable backups
  27. set backupdir=~/.vim/backups "backup directory
  28. set directory=~/.vim/tmp "directory to place swap files in
  29. "Encoding settings
  30. if has("multi_byte")
  31. if &termencoding == ""
  32. let &termencoding = &encoding
  33. endif
  34. set encoding=utf-8
  35. setglobal fileencoding=utf-8 bomb
  36. set fileencodings=ucs-bom,utf-8,default,latin1
  37. endif
  38. "Syntax highlight
  39. syntax on
  40. set t_Co=256
  41. set bg=dark
  42. colorscheme xoria256
  43. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  44. " Interface Settings
  45. "
  46. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  47. set title "show title
  48. set number "show line numbers
  49. set ruler "statusline for each window
  50. set visualbell t_vb= "visual beep
  51. set showcmd "show incomplete commands
  52. set confirm "raise a dialog asking what to do instead of failing
  53. "set mouse=a "enable mouse support
  54. set lazyredraw "do not redraw when running macros
  55. set ttyfast "fast terminal connection support
  56. set shortmess=a "abbreviations on status line
  57. set laststatus=2 "always statusline
  58. set statusline=%<%F\ %h%m%r%y%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
  59. set wildmenu "display completion menu
  60. set wildmode=list:longest,list:full "content of completion menu
  61. "ignore some extensions while completing filename
  62. "set wildignore=*.o,*.so,,*.gz,*.bz2,*.tar,*.tgz,*.tbz2,*.png,*.jpg,*.jpeg,*.gif
  63. set wildchar=<TAB> "wildcar expansion character
  64. set modeline "allow last lines of documents set vim mode
  65. set modelines=3 "number of lines to check for modelines
  66. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  67. " Keyboard Settings
  68. "
  69. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  70. " keep ctrl-a/ctrl-e for begining/end of line
  71. nmap <C-a> <C-o>I
  72. imap <C-a> <C-o>I
  73. vmap <C-a> <C-o>I
  74. nmap <C-e> <C-o>A
  75. imap <C-e> <C-o>A
  76. vmap <C-e> <C-o>A
  77. "reopen current file
  78. map <F5> :e!<CR>
  79. "using redraw to disable highlighted search patterns
  80. nnoremap <C-L> :nohl<CR><C-L>
  81. "map F1 to open previous buffer
  82. nmap <F1> :bp<CR>
  83. imap <F1> <ESC>:bp<CR>a
  84. "map F2 to open next buffer
  85. nmap <F2> :bn<CR>
  86. imap <F2> <ESC>:bn<CR>a
  87. "imap <C-Space> <C-X><C-O> "smart completion
  88. nmap <C-u> :u<CR>
  89. imap <C-u> <ESC>:u<CR>
  90. nmap <C-i> :tabnext<CR>
  91. "nmap <C-S-i> :tabprevious<CR>
  92. nmap <C-t> :tabnew<CR>
  93. "nmap <C-M-w> :tabclose<CR>
  94. nmap <C-q> :call CleanClose()<CR>
  95. nmap <F6> :vsplit<CR>
  96. nmap <F7> :split<CR>
  97. "ctrl-$arrow no cycle around splitted windows
  98. map <C-left> <C-W>h
  99. map <C-right> <C-W>l
  100. map <C-Up> <C-W>k
  101. map <C-Down> <C-W>j
  102. "ident in visual mode keep selection
  103. vmap > >gv
  104. vmap < <gv
  105. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  106. " Editor Settings
  107. "
  108. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  109. set fileformats=unix,dos,mac "support all three, in this order
  110. set hidden "make possible to change buffer without saving
  111. set backspace=indent,eol,start "enhance backspacing
  112. set report=0 "agressive reporting
  113. set pastetoggle=<F11> "use <F11> to toggle between 'paste' and 'nopaste'
  114. set nostartofline "leave the cursor where it is
  115. "indent settings
  116. set autoindent
  117. set smartindent
  118. set cindent
  119. "tabs and spaces settings
  120. set expandtab "tab are spaces
  121. set tabstop=4
  122. set shiftwidth=4
  123. set shiftround "round indent to shiftwidth
  124. set softtabstop=4
  125. set showmatch "brace/parenthese/bracket matching
  126. set nowrap "wrap long lines
  127. if has("multi_byte")
  128. set showbreak="…"
  129. else
  130. set showbreak="+++"
  131. endif
  132. "show some not printable chars
  133. set list
  134. if has("multi_byte")
  135. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:→\
  136. else
  137. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  138. endif
  139. "search settings
  140. set hlsearch "highlight searches
  141. set incsearch "incremental searches
  142. set ignorecase "ignore case in search patterns
  143. set infercase "smart case support
  144. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  145. " Code folding
  146. "
  147. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  148. set foldmethod=indent "fold based on indent
  149. set foldnestmax=10 "deepest fold is 10 levels
  150. set nofoldenable "dont fold by default
  151. set foldlevel=1
  152. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  153. " Email Settings
  154. "
  155. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  156. if has('autocmd')
  157. autocmd BufRead ~/.mutt/tmp/mutt-* set filetype=mail
  158. autocmd FileType mail set autoindent expandtab formatoptions=tcqn
  159. autocmd FileType mail vmap D dO[...]<CR>
  160. autocmd FileType mail call EnableSpellChecking()
  161. endif
  162. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  163. " Filetypes Settings
  164. "
  165. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  166. filetype plugin indent on
  167. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  168. " Global Triggers
  169. "
  170. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  171. if has('autocmd')
  172. "reload Vim config file after saving
  173. autocmd BufWritePost $MYVIMRC :source $MYVIMRC
  174. "always limit the width for text files
  175. autocmd BufRead *.txt set tw=78
  176. autocmd QuickFixCmdPre * botright cwindow 5
  177. endif
  178. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  179. " Spell Checking
  180. "
  181. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  182. "set spellfile=~/.vim/spell/words
  183. function! EnableSpellChecking()
  184. setlocal spell spelllang=fr,en_us
  185. let b:spell = 1
  186. endfunction
  187. function! DisableSpellChecking()
  188. setlocal nospell
  189. unlet b:spell
  190. endfunction
  191. function! ToggleSpell()
  192. if !exists("b:spell")
  193. execute 'call EnableSpellChecking()'
  194. else
  195. execute 'call DisableSpellChecking()'
  196. endif
  197. endfunction
  198. nmap <F4> :call ToggleSpell()<CR>
  199. imap <F4> <Esc>:call ToggleSpell()<CR>a
  200. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  201. " TagList setup
  202. "
  203. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  204. " Settings for taglist.vim
  205. " Define ctags parser path
  206. let Tlist_Ctags_Cmd = "~/.vim/bin/ctags-exuberant"
  207. "Tlist pane get focus on toggle
  208. let Tlist_GainFocus_On_ToggleOpen = 1
  209. " Tlist pane is closed once something is selected
  210. "let Tlist_Close_On_Select = 1
  211. " vim exists if the Tlist window is the last remaining
  212. let Tlist_Exit_OnlyWindow = 1
  213. " highlight current position in tag list
  214. let Tlist_Auto_Highlight_Tag = 1
  215. " Update the tag list regularly
  216. let Tlist_Auto_Update = 0
  217. " remove empty lines on Tlist pane
  218. let Tlist_Compact_Format = 1
  219. " show functions/methods signatures
  220. "let Tlist_Display_Prototype = 1
  221. " show only the tags for the current buffer
  222. let Tlist_Show_One_File = 1
  223. " Tlist pane width
  224. let Tlist_WinWidth = 50
  225. " toggle Tlist with F9
  226. nnoremap <silent> <F9> :Tlist<CR>
  227. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  228. " Useful functions
  229. "
  230. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  231. function! CleanClose()
  232. let todelbufNr = bufnr("%")
  233. let newbufNr = bufnr("#")
  234. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  235. exe "b".newbufNr
  236. else
  237. bnext
  238. endif
  239. if (bufnr("%") == todelbufNr)
  240. new
  241. endif
  242. exe "bd".todelbufNr
  243. endfunction
  244. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  245. " Load pathogen
  246. "
  247. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  248. if filereadable($HOME . "/.vim/bundle/pathogen/autoload/pathogen.vim")
  249. source ~/.vim/bundle/pathogen/autoload/pathogen.vim
  250. call pathogen#infect()
  251. endif
  252. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  253. " Gundo Setup
  254. "
  255. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  256. " Gundo sidebar on the right
  257. let g:gundo_right = 1
  258. " Gundo layout
  259. let g:gundo_width = 60
  260. let g:gundo_preview_height = 40
  261. " Gundo status lines
  262. let g:gundo_tree_statusline = "Gundo"
  263. let g:gundo_preview_statusline = "Gundo Preview"
  264. " Preview pane below the buffer
  265. let g:gundo_preview_bottom = 1
  266. " Close Gundo panes on revert
  267. let g:gundo_close_on_revert = 1
  268. " F3 key to show/hide Gundo sidebar
  269. nnoremap <F3> :GundoToggle<CR>
  270. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  271. " Gundo Setup
  272. "
  273. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  274. " automatically open/close pane when errors (or not)
  275. let g:syntastic_auto_loc_list = 1
  276. " Redefine errors/warning symbols on sidebar
  277. let g:syntastic_error_symbol = 'EE'
  278. let g:syntastic_style_error_symbol = 'ee'
  279. let g:syntastic_warning_symbol = 'WW'
  280. let g:syntastic_style_warning_symbol = 'Ws'
  281. " redefine default python linter
  282. "let g:syntastic_python_checker = 'pylint'
  283. " add options to python linter
  284. "let g:syntastic_python_checker_args = ''