vimrc 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. "
  2. " Vim configuration file
  3. "
  4. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  5. " Useful functions
  6. "
  7. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  8. function! CleanClose()
  9. let todelbufNr = bufnr("%")
  10. let newbufNr = bufnr("#")
  11. if ((newbufNr != -1) && (newbufNr != todelbufNr) && buflisted(newbufNr))
  12. exe "b".newbufNr
  13. else
  14. bnext
  15. endif
  16. if (bufnr("%") == todelbufNr)
  17. new
  18. endif
  19. exe "bd".todelbufNr
  20. endfunction
  21. function! GetFileSize()
  22. let size = ''
  23. let bytes = getfsize(expand('%:p'))
  24. if bytes <= 1024
  25. let size = bytes . 'B'
  26. elseif bytes <= 1048576
  27. let size = (bytes / 1024) . 'KB'
  28. elseif bytes <= (1073741824)
  29. let size = (bytes / 1048576) . 'MB'
  30. elseif bytes <= 1099511627776
  31. let size = (bytes / 1073741824) . 'GB'
  32. elseif bytes <= 1125899906842624
  33. let size = (bytes / 1099511627776) . 'TB'
  34. endif
  35. return size
  36. endfunction
  37. function! GetMode()
  38. let curmode = mode()
  39. let mode = curmode
  40. if curmode == 'n'
  41. let mode = 'NORMAL'
  42. elseif curmode == 'i'
  43. let mode = 'INSERT'
  44. elseif curmode == 'R'
  45. let mode = 'REPLACE'
  46. elseif curmode == 'v'
  47. let mode = 'VISUAL'
  48. elseif curmode == 'V'
  49. if has("multi_byte")
  50. let mode = 'V⋅LINE'
  51. else
  52. let mode = 'VLINE'
  53. endif
  54. elseif curmode == 'V'
  55. if has("multi_byte")
  56. let mode = 'V⋅BLOC'
  57. else
  58. let mode = 'VBLOC'
  59. endif
  60. endif
  61. return mode
  62. endfunction
  63. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  64. " General Settings
  65. "
  66. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  67. "Term settings (under tmux)
  68. if &term =~ '^screen'
  69. "tmux will send xterm-style keys when its xterm-keys option is on
  70. execute "set <xUp>=\e[1;*A"
  71. execute "set <xDown>=\e[1;*B"
  72. execute "set <xRight>=\e[1;*C"
  73. execute "set <xLeft>=\e[1;*D"
  74. endif
  75. set nocompatible "no vi compatibility
  76. set history=200 "command history size
  77. set undolevels=120 "undo levels count
  78. set autoread "notify file changes
  79. set autochdir "switch to the current file directory
  80. set clipboard+=unnamed "share system clipboard
  81. set backup "enable backups
  82. set backupdir=$HOME/tmp "backup directory
  83. set directory=$HOME/tmp "directory to place swap files in
  84. set viminfo+=n$HOME/tmp/.viminfo "viminfo path
  85. "Encoding settings
  86. if has("multi_byte")
  87. if &termencoding == ""
  88. let &termencoding = &encoding
  89. endif
  90. set encoding=utf-8
  91. setglobal fileencoding=utf-8
  92. set fileencodings=utf-8,default,latin1,ucs-bom
  93. endif
  94. "Syntax highlight
  95. syntax on
  96. set t_Co=256
  97. set bg=dark
  98. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  99. " Interface Settings
  100. "
  101. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  102. set title "show title
  103. set number "show line numbers
  104. set ruler "statusline for each window
  105. set visualbell t_vb= "visual beep
  106. set showcmd "show incomplete commands
  107. set confirm "raise a dialog asking what to do instead of failing
  108. "set mouse=a "enable mouse support
  109. set lazyredraw "do not redraw when running macros
  110. set ttyfast "fast terminal connection support
  111. set shortmess=a "abbreviations on status line
  112. set laststatus=2 "always statusline
  113. set statusline=
  114. set statusline+=\ %<%F\ %h%m%r%y%w
  115. if version >= 730
  116. set statusline+=%q
  117. endif
  118. set statusline+=\ [%{GetMode()}(%n,%{mode()})]
  119. "set statusline+=\ %{fugitive#statusline()}
  120. set statusline+=%=
  121. set statusline+=[
  122. set statusline+=%{&fileformat}
  123. set statusline+=,%{&fenc==\"\"?&enc:&fenc}
  124. set statusline+=%{(exists(\"+bomb\")\ &&\ &bomb)?\",bom\":\"\"}
  125. set statusline+=%{(exists(\"+binary\")\ &&\ &binary)?\",bin\":\"\"}
  126. set statusline+=%{&endofline==1?\",eol\":\",noeol\"}
  127. set statusline+=]
  128. set statusline+=\ %{GetFileSize()}
  129. set statusline+=\ %k\ %-14.(%l/%L,%c%V%)\ %P\ %3p%%
  130. set wildmenu "display completion menu
  131. set wildmode=list:longest,list:full "content of completion menu
  132. "ignore some extensions while completing filename
  133. "set wildignore=*.o,*.so,,*.gz,*.bz2,*.tar,*.tgz,*.tbz2,*.png,*.jpg,*.jpeg,*.gif
  134. set wildchar=<TAB> "wildcar expansion character
  135. set modeline "allow last lines of documents set vim mode
  136. set modelines=3 "number of lines to check for modelines
  137. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  138. " Keyboard Settings
  139. "
  140. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  141. " keep ctrl-a/ctrl-e for begining/end of line
  142. nmap <c-a> <c-o>I
  143. imap <c-a> <c-o>I
  144. vmap <c-a> <c-o>I
  145. nmap <c-e> <c-o>A
  146. imap <c-e> <c-o>A
  147. vmap <c-e> <c-o>A
  148. "reopen current file
  149. map <F5> :e!<cr>
  150. "using redraw to disable highlighted search patterns
  151. nnoremap <c-L> :nohl<cr><c-L>
  152. "map F1 to open previous buffer
  153. nmap <F1> :bp<cr>
  154. imap <F1> <ESC>:bp<cr>a
  155. "map F2 to open next buffer
  156. nmap <F2> :bn<cr>
  157. imap <F2> <ESC>:bn<cr>a
  158. imap <c-@> <c-x><c-o>
  159. nmap <c-s-left> :tabprevious<cr>
  160. nmap <c-s-right> :tabnext<cr>
  161. nmap <c-s-up> :tabnew<cr>
  162. nmap <c-s-down> :tabclose<cr>
  163. nmap <c-x> :bw<cr>
  164. nmap <c-end> :call CleanClose()<CR>
  165. nmap <F6> :vsplit<cr>
  166. nmap <F7> :split<cr>
  167. "ctrl-$arrow to cycle around splitted windows
  168. map <c-left> <c-w>h
  169. map <c-right> <c-w>l
  170. map <c-Up> <c-w>k
  171. map <c-Down> <c-w>j
  172. "ident in visual mode keep selection
  173. vmap > >gv
  174. vmap < <gv
  175. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  176. " Editor Settings
  177. "
  178. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  179. set fileformats=unix,dos,mac "support all three, in this order
  180. set hidden "make possible to change buffer without saving
  181. set backspace=indent,eol,start "enhance backspacing
  182. set report=0 "agressive reporting
  183. set pastetoggle=<F11> "use <F11> to toggle between 'paste' and 'nopaste'
  184. set nostartofline "leave the cursor where it is
  185. "indent settings
  186. set autoindent
  187. set smartindent
  188. set cindent
  189. "tabs and spaces settings
  190. set expandtab "tab are spaces
  191. set tabstop=4
  192. set shiftwidth=4
  193. set shiftround "round indent to shiftwidth
  194. set softtabstop=4
  195. set showmatch "brace/parenthese/bracket matching
  196. set nowrap "wrap long lines
  197. if has("multi_byte")
  198. set showbreak="…"
  199. else
  200. set showbreak="+++"
  201. endif
  202. "show some not printable chars
  203. set list
  204. if has("multi_byte")
  205. set listchars=trail:·,extends:>,precedes:<,nbsp:•,tab:▷\⋅
  206. else
  207. set listchars=tab:>.,trail:·,extends:>,precedes:<,nbsp:%
  208. endif
  209. "search settings
  210. set hlsearch "highlight searches
  211. set incsearch "incremental searches
  212. set ignorecase "ignore case in search patterns
  213. set infercase "smart case support
  214. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  215. " Code folding
  216. "
  217. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  218. set foldmethod=indent "fold based on indent
  219. set foldnestmax=10 "deepest fold is 10 levels
  220. set nofoldenable "dont fold by default
  221. set foldlevel=1
  222. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  223. " Filetypes Settings
  224. "
  225. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  226. filetype plugin indent on