vimrc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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 tabstop=4
  113. set shiftwidth=4
  114. set shiftround "round indent to shiftwidth
  115. set softtabstop=4
  116. set showmatch "brace/parenthese/bracket matching
  117. set nowrap "wrap long lines
  118. if has("multi_byte")
  119. set showbreak="…"
  120. else
  121. set showbreak="+++"
  122. endif
  123. "show some not printable chars
  124. set list
  125. if has("multi_byte")
  126. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:→\
  127. else
  128. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  129. endif
  130. "search settings
  131. set hlsearch "highlight searches
  132. set incsearch "incremental searches
  133. set ignorecase "ignore case in search patterns
  134. set infercase "smart case support
  135. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  136. " Email Settings
  137. "
  138. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  139. if has('autocmd')
  140. autocmd BufRead ~/.mutt/tmp/mutt-* set filetype=mail
  141. autocmd FileType mail set autoindent expandtab formatoptions=tcqna
  142. autocmd FileType mail vmap D dO[...]<CR>
  143. autocmd FileType mail call EnableSpellChecking()
  144. endif
  145. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  146. " Filetypes Settings
  147. "
  148. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  149. filetype plugin indent on
  150. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  151. " Global Triggers
  152. "
  153. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  154. if has('autocmd')
  155. "reload Vim config file after saving
  156. autocmd BufWritePost $MYVIMRC :source $MYVIMRC
  157. "always limit the width for text files
  158. autocmd BufRead *.txt set tw=78
  159. autocmd QuickFixCmdPre * botright cwindow 5
  160. endif
  161. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  162. " Spell Checking
  163. "
  164. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  165. "set spellfile=~/.vim/spell/words
  166. function! EnableSpellChecking()
  167. setlocal spell spelllang=fr,en_us
  168. let b:spell = 1
  169. endfunction
  170. function! DisableSpellChecking()
  171. setlocal nospell
  172. unlet b:spell
  173. endfunction
  174. function! ToggleSpell()
  175. if !exists("b:spell")
  176. execute 'call EnableSpellChecking()'
  177. else
  178. execute 'call DisableSpellChecking()'
  179. endif
  180. endfunction
  181. nmap <F4> :call ToggleSpell()<CR>
  182. imap <F4> <Esc>:call ToggleSpell()<CR>a
  183. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  184. " TagList setup
  185. "
  186. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  187. " Settings for taglist.vim
  188. let Tlist_Use_Right_Window=1
  189. let Tlist_Auto_Open=0
  190. "let Tlist_Enable_Fold_Column=0
  191. let Tlist_Compact_Format=1
  192. "let Tlist_WinWidth=28
  193. let Tlist_Exit_OnlyWindow=1
  194. let Tlist_File_Fold_Auto_Close=1
  195. let Tlist_Process_File_Always=1
  196. "dip F1 to open previous buffersplay tags only for the current buffer
  197. let Tlist_Show_One_File=1
  198. let Tlist_Use_SingleClick=1
  199. let Tlist_Ctags_Cmd="~/.vim/bin/ctags-exuberant"
  200. nnoremap <silent> <F9> :Tlist<CR>
  201. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  202. " Useful functions
  203. "
  204. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  205. function! CleanClose()
  206. let todelbufNr = bufnr("%")
  207. let newbufNr = bufnr("#")
  208. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  209. exe "b".newbufNr
  210. else
  211. bnext
  212. endif
  213. if (bufnr("%") == todelbufNr)
  214. new
  215. endif
  216. exe "bd".todelbufNr
  217. endfunction