vimrc 11 KB

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