vimrc 6.6 KB

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