1. "Use Vim settings, rather then Vi settings (much better!).
  2. "This must be first, because it changes other options as a side effect.
  3. set nocompatible
  4. source $VIMRUNTIME/mswin.vim
  5. behave mswin
  6. " Change home directory
  7. let $HOME = $VIM . '/home'
  8. " Disable localvimrc if it's here because we will load it later in the script
  9. let hasLvimrc = filereadable('_lvimrc')
  10. if hasLvimrc
  11. let g:pathogen_disabled = ['localvimrc']
  12. endif
  13. " Start Pathogen First!
  14. source $VIM/bundle/pathogen.vim
  15. runtime $VIM/bundle/pathogen.vim
  16. call pathogen#infect('$VIM/bundle')
  17. " Put these in an autocmd group, so that we can delete them easily.
  18. augroup vimrcEx
  19. au!
  20. " When editing a file, always jump to the last known cursor position.
  21. " Don't do it when the position is invalid or when inside an event handler
  22. " (happens when dropping a file on gvim).
  23. " Also don't do it when the mark is in the first line, that is the default
  24. " position when opening a file.
  25. autocmd BufReadPost *
  26. \ if line("'\"") > 1 && line("'\"") <= line("$") |
  27. \ exe "normal! g`\"" |
  28. \ endif
  29. augroup END
  30. " ----- ----- ----- -----
  31. " Behavior
  32. " ----- ----- ----- -----
  33. filetype plugin indent on " Important for a lot of things
  34. set incsearch " Do incremental searching
  35. set ignorecase " Ignore case when searching, but search capital if used
  36. set smartcase " But use it when there is uppercase
  37. set grepprg=grep\ -rnH " Use grep instead of findstr
  38. set history=50 " Keep 50 lines of command line history
  39. set wildmenu " Auto complete on command line
  40. set wildignore+=*.swp,.git,.svn,*.pyc,*.png,*.jpg,*.gif,*.psd,desktop.ini " Ignore these files when searching
  41. " Disable backup litters
  42. set nobackup
  43. set writebackup
  44. set hidden " Don't unload buffer when it's hidden
  45. " Delete empty buffers, specially for files opened with --remote option
  46. autocmd BufAdd * :call <SID>DeleteBufferIfEmpty()
  47. function s:DeleteBufferIfEmpty()
  48. if bufname('%') == ''
  49. bwipe
  50. " This will trigger filetype detection, mainly to trigger syntax highlighting
  51. doautocmd BufRead
  52. endif
  53. endfunction
  54. autocmd BufWritePre *.js,*.php :%s/\s\+$//e " Remove trailing space before saving
  55. autocmd BufWritePre *.js,*.php :%s/^\s\+$//e " Remove empty line
  56. " ----- ----- ----- -----
  57. " GUI
  58. " ----- ----- ----- -----
  59. if has('gui_running')
  60. set guifont=Consolas:h10:cANSI
  61. colorscheme molokus
  62. endif
  63. " In many terminal emulators the mouse works just fine, thus enable it.
  64. if has('mouse')
  65. set mouse=a
  66. endif
  67. " Switch syntax highlighting on, when the terminal has colors
  68. " Also switch on highlighting the last used search pattern.
  69. if &t_Co > 2 || has("gui_running")
  70. syntax on
  71. set hlsearch
  72. endif
  73. " Give alt key control to Windows
  74. au GUIEnter * simalt ~x
  75. " Make the cursor look nicer
  76. set guicursor=i:ver1
  77. set guicursor=v:hor50
  78. " Highlight current line
  79. " set cursorline " this will cause MiniBufferExpl to have problem
  80. autocmd InsertLeave * set nocursorline
  81. autocmd InsertEnter * set cursorline
  82. " Line number
  83. set number
  84. set nuw=5
  85. set guioptions+=emrb " menu, right & bottom scrollbar
  86. set guioptions-=LtT
  87. set guitablabel=%-0.12t%M " format of tab label
  88. set showtabline=1 " show tabs only if there are more than one
  89. set ruler " show the cursor position all the time
  90. set showcmd " display incomplete commands
  91. " ----- ----- ----- -----
  92. " Text
  93. " ----- ----- ----- -----
  94. " Wordwrap
  95. set lbr
  96. " Indentation
  97. set tabstop=4
  98. set shiftwidth=4
  99. set softtabstop=4
  100. set smartindent
  101. set autoindent
  102. set nocindent
  103. " Folding
  104. set foldmethod=indent
  105. set foldnestmax=5
  106. set foldlevel=9 " prefer to be open by default
  107. set nofoldenable " disable by default
  108. " ----- ----- ----- -----
  109. " Remapping
  110. " ----- ----- ----- -----
  111. " Use 0 to move to first non-whitespace since I already have home button
  112. nnoremap 0 ^
  113. vnoremap 0 ^
  114. " Auto complete
  115. inoremap <c-space> <c-x><c-o>
  116. imap <expr> <tab> pumvisible() ? "<c-n>" : "<tab>"
  117. imap <expr> <s-tab> pumvisible() ? "<c-p>" : "<s-tab>"
  118. " Swap quote with backtick so it's easier to move to column
  119. noremap ' `
  120. vnoremap ' `
  121. noremap ` '
  122. vnoremap ` '
  123. " Don't use Ex mode, use Q for formatting
  124. map Q gq
  125. " Shorter undo sequence. Use CTRL-G u to break undo sequence. :h i_CTRL-G_u http://vim.wikia.com/wiki/Modified_undo_behavior
  126. inoremap <c-u> <c-g>u<c-u>
  127. inoremap <c-w> <c-g>u<c-w>
  128. inoremap <cr> <c-g>u<cr>
  129. inoremap ' <c-g>u'
  130. inoremap " <c-g>u"
  131. inoremap . <c-g>u.
  132. inoremap , <c-g>u,
  133. inoremap = <c-g>u=
  134. inoremap ( <c-g>u(
  135. inoremap [ <c-g>u[
  136. inoremap { <c-g>u{
  137. " inoremap ) <c-g>u)
  138. " inoremap ] <c-g>u]
  139. " inoremap } <c-g>u}
  140. " ----- ----- ----- -----
  141. " Plugins
  142. " ----- ----- ----- -----
  143. " Sessions
  144. ca SO SessionOpen
  145. ca SS SessionSave
  146. " au VimLeave * :SessionSave " auto-save
  147. " ctrlp
  148. let g:ctrlp_open_multiple_files = 'i'
  149. let g:ctrlp_by_filename = 1
  150. " EasyMotion
  151. let g:EasyMotion_leader_key = '<Leader>'
  152. let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyz'
  153. " Zen Coding
  154. let g:user_zen_leader_key = '<c-y>'
  155. let g:user_zen_expandabbr_key = '<c-e>'
  156. let g:use_zen_complete_tag = 1
  157. " Comments
  158. nmap <leader>c <c-_><c-_>
  159. imap <leader>c <c-o><c-_><c-_>
  160. vmap <leader>c <c-_><c-_>
  161. " localvimrc
  162. let g:localvimrc_name = '_lvimrc'
  163. let g:localvimrc_count = 1
  164. let g:localvimrc_sandbox = 0
  165. let g:localvimrc_ask = 0
  166. " neocomplcache
  167. let g:neocomplcache_enable_at_startup = 1
  168. let g:neocomplcache_enable_smart_case = 1
  169. let g:neocomplcache_enable_camel_case_completion = 1
  170. " higher value = higher priority
  171. " swap priority of syntax and buffer complete
  172. let g:neocomplcache_source_rank = {
  173. \ 'buffer_complete': 7,
  174. \ 'syntax_complete': 5
  175. \ }
  176. " MiniBufferExpl
  177. inoremap <c-tab> <esc>:bn!<cr>
  178. vnoremap <c-tab> <esc>:bn!<cr>
  179. nnoremap <c-tab> :bn!<cr>
  180. inoremap <c-s-tab> <esc>:bp!<cr>
  181. vnoremap <c-s-tab> <esc>:bp!<cr>
  182. nnoremap <c-s-tab> :bp!<cr>
  183. let g:miniBufExplUseSingleClick = 1
  184. let g:miniBufExplMapWindowNavVim = 1 " ctrl hjkl
  185. hi MBEVisibleActive guifg=#000000 guibg=#a0a0a0 gui=bold
  186. hi MBEVisibleChangedActive guifg=#000000 guibg=#a0a0a0 gui=bold,italic
  187. hi MBEVisibleNormal guifg=#d0d0d0 guibg=#444444 gui=bold
  188. hi MBEVisibleChanged guifg=#f0f0f0 guibg=#444444 gui=bold,italic
  189. hi MBENormal guifg=#d0d0d0 guibg=#000000
  190. hi MBEChanged guifg=#f0f0f0 guibg=#000000 gui=bold,italic
  191. let g:miniBufExplCheckDupeBufs = 0
  192. " Toggle g:miniBufExplCheckDupeBufs because sometimes it get very slow
  193. map <F12> :call ToggleMiniBufExplCheckDupeBufs()<cr>
  194. function ToggleMiniBufExplCheckDupeBufs()
  195. if g:miniBufExplCheckDupeBufs == 1
  196. let g:miniBufExplCheckDupeBufs = 0
  197. else
  198. let g:miniBufExplCheckDupeBufs = 1
  199. endif
  200. endfunction
  201. " supertab
  202. " I prefer this order of cycling through
  203. " let g:SuperTabMappingBackward = '<tab>'
  204. " let g:SuperTabMappingForward = '<s-tab>'
  205. " Auto highlight first match
  206. " let g:SuperTabLongestHighlight = 1
  207. " ----- ----- ----- -----
  208. " Others
  209. " ----- ----- ----- -----
  210. " Get syntax under cursor
  211. " map <F4> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>
  212. " Vim default diff does not work well
  213. set diffexpr=MyDiff()
  214. function MyDiff()
  215. let opt = '-a --binary '
  216. if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  217. if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  218. let arg1 = v:fname_in
  219. if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif
  220. let arg2 = v:fname_new
  221. if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif
  222. let arg3 = v:fname_out
  223. if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif
  224. let eq = ''
  225. if $VIMRUNTIME =~ ' '
  226. if &sh =~ '\<cmd'
  227. let cmd = '\"' . $VIMRUNTIME . '\diff\"'
  228. let eq = '\"\"'
  229. else
  230. let cmd = substitute($VIMRUNTIME, ' ', '\" ', '') . '\diff\"'
  231. endif
  232. else
  233. let cmd = $VIMRUNTIME . '\diff'
  234. endif
  235. silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
  236. endfunction
  237. " ----- ----- ----- -----
  238. " _lvimrv
  239. " ----- ----- ----- -----
  240. " we still need this becuase localvimrc does not load fast enough
  241. if hasLvimrc
  242. source _lvimrc
  243. endif