vimrc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  10. " Useful functions
  11. "
  12. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  13. function! CleanClose()
  14. let todelbufNr = bufnr("%")
  15. let newbufNr = bufnr("#")
  16. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  17. exe "b".newbufNr
  18. else
  19. bnext
  20. endif
  21. if (bufnr("%") == todelbufNr)
  22. new
  23. endif
  24. exe "bd".todelbufNr
  25. endfunction
  26. function! GetFileSize()
  27. let size = ''
  28. let bytes = getfsize(expand('%:p'))
  29. if bytes <= 1024
  30. let size = bytes . 'B'
  31. elseif bytes <= 1048576
  32. let size = (bytes / 1024) . 'KB'
  33. elseif bytes <= (1073741824)
  34. let size = (bytes / 1048576) . 'MB'
  35. elseif bytes <= 1099511627776
  36. let size = (bytes / 1073741824) . 'GB'
  37. elseif bytes <= 1125899906842624
  38. let size = (bytes / 1099511627776) . 'TB'
  39. endif
  40. return size
  41. endfunction
  42. function! GetMode()
  43. let curmode = mode()
  44. let mode = curmode
  45. if curmode == 'n'
  46. let mode = 'NORMAL'
  47. elseif curmode == 'i'
  48. let mode = 'INSERT'
  49. elseif curmode == 'R'
  50. let mode = 'REPLACE'
  51. elseif curmode == 'v'
  52. let mode = 'VISUAL'
  53. elseif curmode == 'V'
  54. if has("multi_byte")
  55. let mode = 'V⋅LINE'
  56. else
  57. let mode = 'VLINE'
  58. endif
  59. elseif curmode == 'V'
  60. if has("multi_byte")
  61. let mode = 'V⋅BLOC'
  62. else
  63. let mode = 'VBLOC'
  64. endif
  65. endif
  66. return mode
  67. endfunction
  68. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  69. " Load extentions through pathogen
  70. "
  71. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  72. if filereadable($HOME . "/.vim/bundle/pathogen/autoload/pathogen.vim")
  73. source ~/.vim/bundle/pathogen/autoload/pathogen.vim
  74. call pathogen#infect()
  75. endif
  76. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  77. " General Settings
  78. "
  79. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  80. "Term settings (under tmux)
  81. if &term =~ '^screen'
  82. "tmux will send xterm-style keys when its xterm-keys option is on
  83. execute "set <xUp>=\e[1;*A"
  84. execute "set <xDown>=\e[1;*B"
  85. execute "set <xRight>=\e[1;*C"
  86. execute "set <xLeft>=\e[1;*D"
  87. endif
  88. set nocompatible "no vi compatibility
  89. set history=200 "command history size
  90. set undolevels=120 "undo levels count
  91. set autoread "notify file changes
  92. set autochdir "switch to the current file directory
  93. set clipboard+=unnamed "share system clipboard
  94. set backup "enable backups
  95. set backupdir=~/.vim/backups "backup directory
  96. set directory=~/.vim/tmp "directory to place swap files in
  97. "Encoding settings
  98. if has("multi_byte")
  99. if &termencoding == ""
  100. let &termencoding = &encoding
  101. endif
  102. set encoding=utf-8
  103. setglobal fileencoding=utf-8
  104. set fileencodings=utf-8,default,latin1,ucs-bom
  105. endif
  106. "Syntax highlight
  107. syntax on
  108. set t_Co=256
  109. set bg=dark
  110. colorscheme xoria256
  111. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  112. " Interface Settings
  113. "
  114. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  115. set title "show title
  116. set number "show line numbers
  117. set ruler "statusline for each window
  118. set visualbell t_vb= "visual beep
  119. set showcmd "show incomplete commands
  120. set confirm "raise a dialog asking what to do instead of failing
  121. "set mouse=a "enable mouse support
  122. set lazyredraw "do not redraw when running macros
  123. set ttyfast "fast terminal connection support
  124. set shortmess=a "abbreviations on status line
  125. set laststatus=2 "always statusline
  126. set statusline=
  127. set statusline+=\ %<%F\ %h%m%r%y%w
  128. if version >= 730
  129. set statusline+=%q
  130. endif
  131. set statusline+=\ [%{GetMode()}(%n,%{mode()})]
  132. set statusline+=\ %{fugitive#statusline()}
  133. set statusline+=%=
  134. set statusline+=[
  135. set statusline+=%{&fileformat}
  136. set statusline+=,%{&fenc==\"\"?&enc:&fenc}
  137. set statusline+=%{(exists(\"+bomb\")\ &&\ &bomb)?\",bom\":\"\"}
  138. set statusline+=%{(exists(\"+binary\")\ &&\ &binary)?\",bin\":\"\"}
  139. set statusline+=%{&endofline==1?\",eol\":\",noeol\"}
  140. set statusline+=]
  141. set statusline+=\ %{GetFileSize()}
  142. set statusline+=\ %k\ %-14.(%l/%L,%c%V%)\ %P\ %3p%%
  143. set wildmenu "display completion menu
  144. set wildmode=list:longest,list:full "content of completion menu
  145. "ignore some extensions while completing filename
  146. "set wildignore=*.o,*.so,,*.gz,*.bz2,*.tar,*.tgz,*.tbz2,*.png,*.jpg,*.jpeg,*.gif
  147. set wildchar=<TAB> "wildcar expansion character
  148. set modeline "allow last lines of documents set vim mode
  149. set modelines=3 "number of lines to check for modelines
  150. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  151. " Keyboard Settings
  152. "
  153. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  154. " keep ctrl-a/ctrl-e for begining/end of line
  155. nmap <c-a> <c-o>I
  156. imap <c-a> <c-o>I
  157. vmap <c-a> <c-o>I
  158. nmap <c-e> <c-o>A
  159. imap <c-e> <c-o>A
  160. vmap <c-e> <c-o>A
  161. "reopen current file
  162. map <F5> :e!<cr>
  163. "using redraw to disable highlighted search patterns
  164. nnoremap <c-L> :nohl<cr><c-L>
  165. "map F1 to open previous buffer
  166. nmap <F1> :bp<cr>
  167. imap <F1> <ESC>:bp<cr>a
  168. "map F2 to open next buffer
  169. nmap <F2> :bn<cr>
  170. imap <F2> <ESC>:bn<cr>a
  171. imap <c-@> <c-x><c-o>
  172. nmap <c-s-left> :tabprevious<cr>
  173. nmap <c-s-right> :tabnext<cr>
  174. nmap <c-s-up> :tabnew<cr>
  175. nmap <c-s-down> :tabclose<cr>
  176. nmap <c-x> :bw<cr>
  177. nmap <c-end> :call CleanClose()<CR>
  178. nmap <F6> :vsplit<cr>
  179. nmap <F7> :split<cr>
  180. "ctrl-$arrow to cycle around splitted windows
  181. map <c-left> <c-w>h
  182. map <c-right> <c-w>l
  183. map <c-Up> <c-w>k
  184. map <c-Down> <c-w>j
  185. "ident in visual mode keep selection
  186. vmap > >gv
  187. vmap < <gv
  188. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  189. " Editor Settings
  190. "
  191. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  192. set fileformats=unix,dos,mac "support all three, in this order
  193. set hidden "make possible to change buffer without saving
  194. set backspace=indent,eol,start "enhance backspacing
  195. set report=0 "agressive reporting
  196. set pastetoggle=<F11> "use <F11> to toggle between 'paste' and 'nopaste'
  197. set nostartofline "leave the cursor where it is
  198. "indent settings
  199. set autoindent
  200. set smartindent
  201. set cindent
  202. "tabs and spaces settings
  203. set expandtab "tab are spaces
  204. set tabstop=4
  205. set shiftwidth=4
  206. set shiftround "round indent to shiftwidth
  207. set softtabstop=4
  208. set showmatch "brace/parenthese/bracket matching
  209. set nowrap "wrap long lines
  210. if has("multi_byte")
  211. set showbreak="…"
  212. else
  213. set showbreak="+++"
  214. endif
  215. "show some not printable chars
  216. set list
  217. if has("multi_byte")
  218. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:▷\⋅
  219. else
  220. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  221. endif
  222. "search settings
  223. set hlsearch "highlight searches
  224. set incsearch "incremental searches
  225. set ignorecase "ignore case in search patterns
  226. set infercase "smart case support
  227. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  228. " Code folding
  229. "
  230. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  231. set foldmethod=indent "fold based on indent
  232. set foldnestmax=10 "deepest fold is 10 levels
  233. set nofoldenable "dont fold by default
  234. set foldlevel=1
  235. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  236. " Email Settings
  237. "
  238. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  239. if has('autocmd')
  240. autocmd BufRead ~/.mutt/tmp/mutt-* set filetype=mail
  241. autocmd FileType mail set autoindent expandtab formatoptions=tcqn
  242. autocmd FileType mail vmap D dO[...]<CR>
  243. autocmd FileType mail call EnableSpellChecking()
  244. endif
  245. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  246. " Filetypes Settings
  247. "
  248. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  249. filetype plugin indent on
  250. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  251. " Global Triggers
  252. "
  253. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  254. if has('autocmd')
  255. "reload Vim config file after saving
  256. autocmd BufWritePost $MYVIMRC :source $MYVIMRC
  257. "always limit the width for text files
  258. autocmd BufRead *.txt set tw=78
  259. autocmd QuickFixCmdPre * botright cwindow 5
  260. endif
  261. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  262. " Spell Checking
  263. "
  264. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  265. "set spellfile=~/.vim/spell/words
  266. function! EnableSpellChecking()
  267. setlocal spell spelllang=fr,en_us
  268. let b:spell = 1
  269. endfunction
  270. function! DisableSpellChecking()
  271. setlocal nospell
  272. unlet b:spell
  273. endfunction
  274. function! ToggleSpell()
  275. if !exists("b:spell")
  276. execute 'call EnableSpellChecking()'
  277. else
  278. execute 'call DisableSpellChecking()'
  279. endif
  280. endfunction
  281. nmap <F4> :call ToggleSpell()<CR>
  282. imap <F4> <Esc>:call ToggleSpell()<CR>a
  283. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  284. " TagList setup
  285. "
  286. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  287. " Settings for taglist.vim
  288. " Define ctags parser path
  289. let Tlist_Ctags_Cmd = "~/.vim/bin/ctags-exuberant"
  290. "Tlist pane get focus on toggle
  291. let Tlist_GainFocus_On_ToggleOpen = 1
  292. " Tlist pane is closed once something is selected
  293. "let Tlist_Close_On_Select = 1
  294. " vim exists if the Tlist window is the last remaining
  295. let Tlist_Exit_OnlyWindow = 1
  296. " highlight current position in tag list
  297. let Tlist_Auto_Highlight_Tag = 1
  298. " Update the tag list regularly
  299. let Tlist_Auto_Update = 0
  300. " remove empty lines on Tlist pane
  301. let Tlist_Compact_Format = 1
  302. " show functions/methods signatures
  303. "let Tlist_Display_Prototype = 1
  304. " show only the tags for the current buffer
  305. let Tlist_Show_One_File = 1
  306. " Tlist pane width
  307. let Tlist_WinWidth = 50
  308. " toggle Tlist with F9
  309. nnoremap <silent> <F9> :Tlist<CR>
  310. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  311. " Gundo extension Setup
  312. "
  313. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  314. " Gundo sidebar on the right
  315. let g:gundo_right = 1
  316. " Gundo layout
  317. let g:gundo_width = 60
  318. let g:gundo_preview_height = 40
  319. " Gundo status lines
  320. let g:gundo_tree_statusline = "Gundo"
  321. let g:gundo_preview_statusline = "Gundo Preview"
  322. " Preview pane below the buffer
  323. let g:gundo_preview_bottom = 1
  324. " Close Gundo panes on revert
  325. let g:gundo_close_on_revert = 1
  326. " F3 key to show/hide Gundo sidebar
  327. nnoremap <F3> :GundoToggle<CR>
  328. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  329. " Syntastic extension Setup
  330. "
  331. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  332. " automatically open/close pane when errors (or not)
  333. let g:syntastic_auto_loc_list = 1
  334. " Redefine errors/warning symbols on sidebar
  335. let g:syntastic_error_symbol = 'EE'
  336. let g:syntastic_style_error_symbol = 'ee'
  337. let g:syntastic_warning_symbol = 'WW'
  338. let g:syntastic_style_warning_symbol = 'Ws'
  339. " redefine default python linter
  340. "let g:syntastic_python_checker = 'pylint'
  341. " add options to python linter
  342. "let g:syntastic_python_checker_args = ''
  343. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  344. " CtrlP extension Setup
  345. "
  346. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  347. " Change default key
  348. let g:ctrlp_map = '<c-o>'
  349. " Match window height
  350. let g:ctrlp_max_height = 20
  351. " Add a key to search in opened buffers
  352. map <c-b> :CtrlPBuffer<cr>
  353. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  354. " Project environment
  355. "
  356. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  357. let g:vim_project_file_name = '.vim_project'
  358. function! GetSubPaths()
  359. let sep = '&'
  360. let paths = ''
  361. let curdir = expand('%:p:h')
  362. while curdir != '/'
  363. let paths = paths . sep . curdir
  364. let curdir = fnamemodify(curdir, ':h')
  365. endwhile
  366. let paths = paths . sep . '/'
  367. return split(paths, sep)
  368. endfunction
  369. function! GetVimProjectDir()
  370. let projectdir = ''
  371. let subpaths = GetSubPaths()
  372. let length = len(subpaths)
  373. let i = 0
  374. while i < length && projectdir == ''
  375. if subpaths[i] == '/'
  376. let projectfile = '/' . g:vim_project_file_name
  377. else
  378. let projectfile = subpaths[i] . '/' . g:vim_project_file_name
  379. endif
  380. if filereadable(projectfile)
  381. let projectdir = subpaths[i]
  382. endif
  383. let i = i + 1
  384. endwhile
  385. if projectdir == ''
  386. let projectdir = getcwd()
  387. endif
  388. return projectdir
  389. endfunction
  390. let g:vim_project_dir = GetVimProjectDir()
  391. let g:vim_project_file = vim_project_dir . '/' . vim_project_file_name
  392. execute 'set tags=' . g:vim_project_dir . '/tags'
  393. if has('autocmd')
  394. execute "autocmd BufRead " . g:vim_project_file_name . " set filetype=vim"
  395. endif
  396. if filereadable(g:vim_project_file)
  397. execute 'source ' . g:vim_project_file
  398. endif