vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. set nocompatible "no vi compatibility
  13. set history=200 "command history size
  14. set undolevels=120 "undo levels count
  15. set autoread "notify file changes
  16. set autochdir "switch to the current file directory
  17. set clipboard+=unnamed "share system clipboard
  18. set backup "enable backups
  19. set backupdir=~/.vim/backups "backup directory
  20. set directory=~/.vim/tmp "directory to place swap files in
  21. "Encoding settings
  22. if has("multi_byte")
  23. if &termencoding == ""
  24. let &termencoding = &encoding
  25. endif
  26. set encoding=utf-8
  27. setglobal fileencoding=utf-8 bomb
  28. set fileencodings=ucs-bom,utf-8,default,latin1
  29. endif
  30. "Syntax highlight
  31. syntax on
  32. set t_Co=256
  33. set bg=dark
  34. colorscheme xoria256
  35. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  36. " Interface Settings
  37. "
  38. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  39. set title "show title
  40. set number "show line numbers
  41. set ruler "statusline for each window
  42. set visualbell t_vb= "visual beep
  43. set showcmd "show incomplete commands
  44. set confirm "raise a dialog asking what to do instead of failing
  45. "set mouse=a "enable mouse support
  46. set lazyredraw "do not redraw when running macros
  47. set ttyfast "fast terminal connection support
  48. set shortmess=a "abbreviations on status line
  49. set laststatus=2 "always statusline
  50. set statusline=%<%F\ %h%m%r%y%=%{\"[\".(&fenc==\"\"?&enc:&fenc).((exists(\"+bomb\")\ &&\ &bomb)?\",B\":\"\").\"]\ \"}%k\ %-14.(%l,%c%V%)\ %P
  51. set wildmenu "display completion menu
  52. set wildmode=list:longest,list:full "content of completion menu
  53. "ignore some extensions while completing filename
  54. "set wildignore=*.o,*.so,,*.gz,*.bz2,*.tar,*.tgz,*.tbz2,*.png,*.jpg,*.jpeg,*.gif
  55. set wildchar=<TAB> "wildcar expansion character
  56. set modeline "allow last lines of documents set vim mode
  57. set modelines=3 "number of lines to check for modelines
  58. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  59. " Keyboard Settings
  60. "
  61. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  62. " keep ctrl-a/ctrl-e for begining/end of line
  63. nmap <C-a> <C-o>I
  64. imap <C-a> <C-o>I
  65. vmap <C-a> <C-o>I
  66. nmap <C-e> <C-o>A
  67. imap <C-e> <C-o>A
  68. vmap <C-e> <C-o>A
  69. "reopen current file
  70. map <F5> :e!<CR>
  71. "using redraw to disable highlighted search patterns
  72. nnoremap <C-L> :nohl<CR><C-L>
  73. "map F1 to open previous buffer
  74. nmap <F1> :bp<CR>
  75. imap <F1> <ESC>:bp<CR>a
  76. "map F2 to open next buffer
  77. nmap <F2> :bn<CR>
  78. imap <F2> <ESC>:bn<CR>a
  79. "imap <C-Space> <C-X><C-O> "smart completion
  80. nmap <C-u> :u<CR>
  81. imap <C-u> <ESC>:u<CR>
  82. nmap <C-i> :tabnext<CR>
  83. "nmap <C-S-i> :tabprevious<CR>
  84. nmap <C-t> :tabnew<CR>
  85. "nmap <C-M-w> :tabclose<CR>
  86. nmap <C-q> :call CleanClose()<CR>
  87. nmap <F6> :vsplit<CR>
  88. nmap <F7> :split<CR>
  89. "ctrl-$arrow no cycle around splitted windows
  90. map <C-left> <C-W>h
  91. map <C-right> <C-W>l
  92. map <C-Up> <C-W>k
  93. map <C-Down> <C-W>j
  94. "ident in visual mode keep selection
  95. vmap > >gv
  96. vmap < <gv
  97. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  98. " Editor Settings
  99. "
  100. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  101. set fileformats=unix,dos,mac "support all three, in this order
  102. set hidden "make possible to change buffer without saving
  103. set backspace=indent,eol,start "enhance backspacing
  104. set report=0 "agressive reporting
  105. set pastetoggle=<F11> "use <F11> to toggle between 'paste' and 'nopaste'
  106. set nostartofline "leave the cursor where it is
  107. "indent settings
  108. set autoindent
  109. set smartindent
  110. set cindent
  111. "tabs and spaces settings
  112. set expandtab "tab are spaces
  113. set tabstop=4
  114. set shiftwidth=4
  115. set shiftround "round indent to shiftwidth
  116. set softtabstop=4
  117. set showmatch "brace/parenthese/bracket matching
  118. set nowrap "wrap long lines
  119. if has("multi_byte")
  120. set showbreak="…"
  121. else
  122. set showbreak="+++"
  123. endif
  124. "show some not printable chars
  125. set list
  126. if has("multi_byte")
  127. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:→\
  128. else
  129. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  130. endif
  131. "search settings
  132. set hlsearch "highlight searches
  133. set incsearch "incremental searches
  134. set ignorecase "ignore case in search patterns
  135. set infercase "smart case support
  136. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  137. " Code folding
  138. "
  139. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  140. set foldmethod=indent "fold based on indent
  141. set foldnestmax=10 "deepest fold is 10 levels
  142. set nofoldenable "dont fold by default
  143. set foldlevel=1
  144. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  145. " Email Settings
  146. "
  147. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  148. if has('autocmd')
  149. autocmd BufRead ~/.mutt/tmp/mutt-* set filetype=mail
  150. autocmd FileType mail set autoindent expandtab formatoptions=tcqn
  151. autocmd FileType mail vmap D dO[...]<CR>
  152. autocmd FileType mail call EnableSpellChecking()
  153. endif
  154. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  155. " Filetypes Settings
  156. "
  157. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  158. filetype plugin indent on
  159. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  160. " Global Triggers
  161. "
  162. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  163. if has('autocmd')
  164. "reload Vim config file after saving
  165. autocmd BufWritePost $MYVIMRC :source $MYVIMRC
  166. "always limit the width for text files
  167. autocmd BufRead *.txt set tw=78
  168. autocmd QuickFixCmdPre * botright cwindow 5
  169. endif
  170. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  171. " Spell Checking
  172. "
  173. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  174. "set spellfile=~/.vim/spell/words
  175. function! EnableSpellChecking()
  176. setlocal spell spelllang=fr,en_us
  177. let b:spell = 1
  178. endfunction
  179. function! DisableSpellChecking()
  180. setlocal nospell
  181. unlet b:spell
  182. endfunction
  183. function! ToggleSpell()
  184. if !exists("b:spell")
  185. execute 'call EnableSpellChecking()'
  186. else
  187. execute 'call DisableSpellChecking()'
  188. endif
  189. endfunction
  190. nmap <F4> :call ToggleSpell()<CR>
  191. imap <F4> <Esc>:call ToggleSpell()<CR>a
  192. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  193. " TagList setup
  194. "
  195. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  196. " Settings for taglist.vim
  197. let Tlist_Use_Right_Window=1
  198. let Tlist_Auto_Open=0
  199. "let Tlist_Enable_Fold_Column=0
  200. let Tlist_Compact_Format=1
  201. "let Tlist_WinWidth=28
  202. let Tlist_Exit_OnlyWindow=1
  203. let Tlist_File_Fold_Auto_Close=1
  204. let Tlist_Process_File_Always=1
  205. "dip F1 to open previous buffersplay tags only for the current buffer
  206. let Tlist_Show_One_File=1
  207. let Tlist_Use_SingleClick=1
  208. let Tlist_Ctags_Cmd="~/.vim/bin/ctags-exuberant"
  209. nnoremap <silent> <F9> :Tlist<CR>
  210. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  211. " Useful functions
  212. "
  213. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  214. function! CleanClose()
  215. let todelbufNr = bufnr("%")
  216. let newbufNr = bufnr("#")
  217. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  218. exe "b".newbufNr
  219. else
  220. bnext
  221. endif
  222. if (bufnr("%") == todelbufNr)
  223. new
  224. endif
  225. exe "bd".todelbufNr
  226. endfunction