vimrc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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-@> <c-x><c-o>
  88. nmap <c-s-left> :tabprevious<cr>
  89. nmap <c-s-right> :tabnext<cr>
  90. nmap <c-s-up> :tabnew<cr>
  91. nmap <c-s-down> :tabclose<cr>
  92. nmap <c-x> :bw<cr>
  93. nmap <F6> :vsplit<cr>
  94. nmap <F7> :split<cr>
  95. "ctrl-$arrow to cycle around splitted windows
  96. map <c-left> <c-w>h
  97. map <c-right> <c-w>l
  98. map <c-Up> <c-w>k
  99. map <c-Down> <c-w>j
  100. "ident in visual mode keep selection
  101. vmap > >gv
  102. vmap < <gv
  103. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  104. " Editor Settings
  105. "
  106. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  107. set fileformats=unix,dos,mac "support all three, in this order
  108. set hidden "make possible to change buffer without saving
  109. set backspace=indent,eol,start "enhance backspacing
  110. set report=0 "agressive reporting
  111. set pastetoggle=<F11> "use <F11> to toggle between 'paste' and 'nopaste'
  112. set nostartofline "leave the cursor where it is
  113. "indent settings
  114. set autoindent
  115. set smartindent
  116. set cindent
  117. "tabs and spaces settings
  118. set expandtab "tab are spaces
  119. set tabstop=4
  120. set shiftwidth=4
  121. set shiftround "round indent to shiftwidth
  122. set softtabstop=4
  123. set showmatch "brace/parenthese/bracket matching
  124. set nowrap "wrap long lines
  125. if has("multi_byte")
  126. set showbreak="…"
  127. else
  128. set showbreak="+++"
  129. endif
  130. "show some not printable chars
  131. set list
  132. if has("multi_byte")
  133. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:→\
  134. else
  135. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  136. endif
  137. "search settings
  138. set hlsearch "highlight searches
  139. set incsearch "incremental searches
  140. set ignorecase "ignore case in search patterns
  141. set infercase "smart case support
  142. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  143. " Code folding
  144. "
  145. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  146. set foldmethod=indent "fold based on indent
  147. set foldnestmax=10 "deepest fold is 10 levels
  148. set nofoldenable "dont fold by default
  149. set foldlevel=1
  150. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  151. " Email Settings
  152. "
  153. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  154. if has('autocmd')
  155. autocmd BufRead ~/.mutt/tmp/mutt-* set filetype=mail
  156. autocmd FileType mail set autoindent expandtab formatoptions=tcqn
  157. autocmd FileType mail vmap D dO[...]<CR>
  158. autocmd FileType mail call EnableSpellChecking()
  159. endif
  160. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  161. " Filetypes Settings
  162. "
  163. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  164. filetype plugin indent on
  165. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  166. " Global Triggers
  167. "
  168. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  169. if has('autocmd')
  170. "reload Vim config file after saving
  171. autocmd BufWritePost $MYVIMRC :source $MYVIMRC
  172. "always limit the width for text files
  173. autocmd BufRead *.txt set tw=78
  174. autocmd QuickFixCmdPre * botright cwindow 5
  175. endif
  176. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  177. " Spell Checking
  178. "
  179. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  180. "set spellfile=~/.vim/spell/words
  181. function! EnableSpellChecking()
  182. setlocal spell spelllang=fr,en_us
  183. let b:spell = 1
  184. endfunction
  185. function! DisableSpellChecking()
  186. setlocal nospell
  187. unlet b:spell
  188. endfunction
  189. function! ToggleSpell()
  190. if !exists("b:spell")
  191. execute 'call EnableSpellChecking()'
  192. else
  193. execute 'call DisableSpellChecking()'
  194. endif
  195. endfunction
  196. nmap <F4> :call ToggleSpell()<CR>
  197. imap <F4> <Esc>:call ToggleSpell()<CR>a
  198. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  199. " TagList setup
  200. "
  201. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  202. " Settings for taglist.vim
  203. " Define ctags parser path
  204. let Tlist_Ctags_Cmd = "~/.vim/bin/ctags-exuberant"
  205. "Tlist pane get focus on toggle
  206. let Tlist_GainFocus_On_ToggleOpen = 1
  207. " Tlist pane is closed once something is selected
  208. "let Tlist_Close_On_Select = 1
  209. " vim exists if the Tlist window is the last remaining
  210. let Tlist_Exit_OnlyWindow = 1
  211. " highlight current position in tag list
  212. let Tlist_Auto_Highlight_Tag = 1
  213. " Update the tag list regularly
  214. let Tlist_Auto_Update = 0
  215. " remove empty lines on Tlist pane
  216. let Tlist_Compact_Format = 1
  217. " show functions/methods signatures
  218. "let Tlist_Display_Prototype = 1
  219. " show only the tags for the current buffer
  220. let Tlist_Show_One_File = 1
  221. " Tlist pane width
  222. let Tlist_WinWidth = 50
  223. " toggle Tlist with F9
  224. nnoremap <silent> <F9> :Tlist<CR>
  225. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  226. " Useful functions
  227. "
  228. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  229. function! CleanClose()
  230. let todelbufNr = bufnr("%")
  231. let newbufNr = bufnr("#")
  232. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  233. exe "b".newbufNr
  234. else
  235. bnext
  236. endif
  237. if (bufnr("%") == todelbufNr)
  238. new
  239. endif
  240. exe "bd".todelbufNr
  241. endfunction
  242. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  243. " Load pathogen
  244. "
  245. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  246. if filereadable($HOME . "/.vim/bundle/pathogen/autoload/pathogen.vim")
  247. source ~/.vim/bundle/pathogen/autoload/pathogen.vim
  248. call pathogen#infect()
  249. endif
  250. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  251. " Gundo extension Setup
  252. "
  253. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  254. " Gundo sidebar on the right
  255. let g:gundo_right = 1
  256. " Gundo layout
  257. let g:gundo_width = 60
  258. let g:gundo_preview_height = 40
  259. " Gundo status lines
  260. let g:gundo_tree_statusline = "Gundo"
  261. let g:gundo_preview_statusline = "Gundo Preview"
  262. " Preview pane below the buffer
  263. let g:gundo_preview_bottom = 1
  264. " Close Gundo panes on revert
  265. let g:gundo_close_on_revert = 1
  266. " F3 key to show/hide Gundo sidebar
  267. nnoremap <F3> :GundoToggle<CR>
  268. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  269. " Syntastic extension Setup
  270. "
  271. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  272. " automatically open/close pane when errors (or not)
  273. let g:syntastic_auto_loc_list = 1
  274. " Redefine errors/warning symbols on sidebar
  275. let g:syntastic_error_symbol = 'EE'
  276. let g:syntastic_style_error_symbol = 'ee'
  277. let g:syntastic_warning_symbol = 'WW'
  278. let g:syntastic_style_warning_symbol = 'Ws'
  279. " redefine default python linter
  280. "let g:syntastic_python_checker = 'pylint'
  281. " add options to python linter
  282. "let g:syntastic_python_checker_args = ''
  283. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  284. " CtrlP extension Setup
  285. "
  286. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  287. " Change default key
  288. let g:ctrlp_map = '<c-o>'
  289. " Match window height
  290. let g:ctrlp_max_height = 20
  291. " Add a key to search in opened buffers
  292. map <c-b> :CtrlPBuffer<cr>