vimrc 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. " Do not try to be compatible with vi
  2. set nocompatible
  3. if has("autocmd")
  4. " Clear existing autocmd
  5. autocmd!
  6. endif
  7. " Initialize directories {
  8. function! InitializeDirectories()
  9. let parent = $HOME
  10. let prefix = 'vim'
  11. let dir_list = {
  12. \ 'backup': 'backupdir',
  13. \ 'swap': 'directory' }
  14. if has('persistent_undo')
  15. let dir_list['undo'] = 'undodir'
  16. endif
  17. let common_dir = parent . '/.' . prefix
  18. for [dirname, settingname] in items(dir_list)
  19. let directory = common_dir . dirname . '/'
  20. if exists("*mkdir")
  21. if !isdirectory(directory)
  22. call mkdir(directory)
  23. endif
  24. endif
  25. if !isdirectory(directory)
  26. echo "Warning: Unable to create backup directory: " . directory
  27. echo "Try: mkdir -p " . directory
  28. else
  29. let directory = substitute(directory, " ", "\\\\ ", "g")
  30. exec "set " . settingname . "=" . directory
  31. endif
  32. endfor
  33. endfunction
  34. call InitializeDirectories()
  35. " }
  36. " Use bundles config {
  37. if filereadable(expand("~/.vimrc.bundles"))
  38. source ~/.vimrc.bundles
  39. endif
  40. " }
  41. filetype plugin indent on " Automatically detect file types.
  42. if has("autocmd")
  43. " Source the vimrc file after saving it
  44. autocmd BufWritePost .vimrc nested source $MYVIMRC
  45. endif
  46. """"""""
  47. "" Tabs and Text Formatting
  48. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  49. syntax on " Syntax highlighting
  50. set background=dark " Assume a dark background
  51. colorscheme solarized
  52. set nowrap
  53. set cursorline " Highlight current line
  54. set expandtab " convert tab characters into spaces
  55. set tabstop=2 " actual tab press distance
  56. set softtabstop=2 " let backspace delete by indents
  57. set shiftround " indent to nearest tabstops
  58. set shiftwidth=2 " amount to indent with > and <
  59. set smarttab " backspace tabs where appropriate even if spaces
  60. set textwidth=80 " try to keep text within 80 characters
  61. set colorcolumn=+1 " mark out the limits of the textwidth
  62. set mouse=a
  63. set nojoinspaces " Prevents inserting two spaces after punctuation on a join (J)
  64. set splitright " Puts new vsplit windows to the right of the current
  65. set splitbelow " Puts new split windows to the bottom of the current
  66. set backspace=indent,eol,start " Backspace for dummies
  67. set linespace=0 " No extra spaces between rows
  68. set number " Line numbers on
  69. set showmatch " Show matching brackets/parenthesis
  70. set incsearch " Find as you type search
  71. set hlsearch " Highlight search terms
  72. set winminheight=0 " Windows can be 0 line high
  73. set ignorecase " Case insensitive search
  74. set smartcase " Case sensitive when uc present
  75. set wildmenu " Show list instead of just completing
  76. "set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
  77. set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
  78. set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
  79. set scrolljump=5 " Lines to scroll when cursor leaves screen
  80. set scrolloff=3 " Minimum lines to keep above and below cursor
  81. set foldenable " Auto fold code
  82. set list
  83. set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
  84. if has('persistent_undo')
  85. set undofile " So is persistent undo ...
  86. set undolevels=1000 " Maximum number of changes that can be undone
  87. set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
  88. endif
  89. """"""""
  90. "" UI - Mouse & Cursor
  91. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  92. " The following two settings are related to how vim reacts to the incoming $TERM
  93. " value from either the terminal emulator (e.g. iTerm2) or tmux. In the best
  94. " case, both of these should be set to xterm-256color. This will result in vim
  95. " reacting with the settings below:
  96. "set ttymouse=xterm2 " Needed to allow mouse support to resize windows
  97. "set ttyfast " Allows for instantaneous refresh when using the mouse to select
  98. """"""""
  99. "" UI - Solarized Fix
  100. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  101. " Fix solarized scheme in spf13-vim. The config sets up to use the degraded
  102. " 256-color mode for sake of some terminal emulators? (see
  103. " https://github.com/spf13/spf13-vim/issues/113).
  104. "
  105. " These two lines Must come in this order or they won't work: number and fold
  106. " columns and cursor line come out brownish (dark scheme) or black (light
  107. " scheme).
  108. "let g:solarized_termcolors=16
  109. "set t_Co=16
  110. """"""""
  111. "" UI - Code Folding
  112. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  113. set foldmethod=indent
  114. set foldlevel=10
  115. """"""""
  116. "" Key Remaps
  117. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  118. let mapleader = ','
  119. " More convenient escape
  120. inoremap kj <ESC>
  121. inoremap jk <ESC>
  122. " Yank from the cursor to the end of the line, to be consistent with C and D.
  123. nnoremap Y y$
  124. " Add extra lines up and down
  125. nnoremap <leader>j o<Esc>k
  126. nnoremap <leader>k O<Esc>j
  127. " Convert tabs to spaces
  128. nnoremap <silent> <leader><TAB> :%s/<TAB>/ /g<CR>
  129. " Backspace to clear current search (and stop highlighting)
  130. nnoremap <silent> <backspace> :call ClearSearch()<CR>
  131. function! ClearSearch()
  132. if (@/ != "")
  133. let @/=""
  134. redraw
  135. endif
  136. endfunction
  137. nnoremap <silent> <leader>w :set wrap!<CR>
  138. " Toggle paste mode - no autoindenting of pasted material
  139. nnoremap <silent> <leader>p :set paste! paste?<CR>
  140. " Toggle visible whitespace characters
  141. nnoremap <silent> <leader>l :set list!<CR>
  142. " Toggle keyboard layout
  143. "nnoremap <silent> <leader><space> :call CycleKeymap()<CR>
  144. "function! CycleKeymap()
  145. "if has('keymap')
  146. "if (&keymap == '')
  147. "set keymap=colemak
  148. "echo 'Colemak keymap selected'
  149. "elseif (&keymap == 'colemak')
  150. "set keymap=dvorak
  151. "echo 'Dvorak keymap selected'
  152. "else
  153. "set keymap=
  154. "echo 'Qwerty keymap selected'
  155. "endif
  156. "else
  157. "echo 'Keymaps not supported'
  158. "endif
  159. "endfunction
  160. " Toggle scrollbind for moving multiple splits in sync together
  161. nnoremap <silent> <leader>sb :set scrollbind! scrollbind?<CR>
  162. " Toggle mouse support.
  163. nnoremap <silent> <leader>m :call ToggleMouse()<CR>
  164. function! ToggleMouse()
  165. if &mouse == 'a'
  166. set mouse=
  167. echo 'Mouse usage disabled'
  168. else
  169. set mouse=a
  170. echo 'Mouse usage enabled'
  171. endif
  172. endfunction
  173. " Toggle NERDTree file browser
  174. nnoremap <silent> <leader>d :NERDTreeMirrorToggle<CR>
  175. let g:NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
  176. let g:NERDTreeChDirMode=0
  177. let g:NERDTreeQuitOnOpen=1
  178. let g:NERDTreeMouseMode=2
  179. let g:NERDTreeShowHidden=1
  180. let g:NERDTreeKeepTreeInNewTab=1
  181. " Toggle Commenting out lines with NERDCommenter
  182. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  183. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  184. " Git commands with Fugitive
  185. nnoremap <silent> <leader>gc :Gcommit -v<CR>
  186. nnoremap <silent> <leader>gl :Glog<CR><CR>
  187. nnoremap <silent> <leader>gap :Git add -p<CR>
  188. nnoremap <silent> <leader>gs :Gstatus<CR>
  189. nnoremap <silent> <leader>gd :Gdiff<CR>
  190. nnoremap <silent> <leader>gb :Gblame<CR>
  191. if has("autocmd")
  192. " Fugitive - Go up to previous tree object while exploring git tree with '..'
  193. autocmd User fugitive
  194. \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
  195. \ nnoremap <buffer> .. :edit %:h<CR> |
  196. \ endif
  197. " Fugitive - Delete buffers when they are not active
  198. autocmd BufReadPost fugitive://* set bufhidden=delete
  199. endif
  200. " Gundo
  201. nnoremap <silent> <leader>u :GundoToggle<CR>
  202. " Tagbar
  203. nnoremap <silent> <leader>t :TagbarToggle<CR>
  204. """"""""" CtrlP
  205. " Function definition jumping with CtrlP's Funky plugin
  206. nnoremap <silent> <C-F> :CtrlPFunky<CR>
  207. "let g:ctrlp_working_path_mode = 'rw' let's try out ra
  208. let g:ctrlp_user_command = {
  209. \ 'types': {
  210. \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
  211. \ 2: ['.hg', 'hg --cwd %s locate -I .'],
  212. \ },
  213. \ 'fallback': 'find %s -type f'
  214. \ }
  215. let g:ctrlp_extensions = ['funky']
  216. """"""""" Powerline
  217. set laststatus=2
  218. set rtp+=~/dotfiles/powerline/powerline/powerline/bindings/vim
  219. set noshowmode " don't show e.g. --INSERT-- since we're using powerline
  220. """"""""" Tagbar
  221. let g:tagbar_autoclose = 1 " close sidebar after we go to selection
  222. """"""""" Indent Guides
  223. let g:indent_guides_enable_on_vim_startup = 1
  224. let g:indent_guides_auto_colors = 0
  225. " reverse indent guides highlighting
  226. "highlight IndentGuidesOdd ctermbg=grey
  227. highlight IndentGuidesEven ctermbg=black
  228. """"""""" Syntastic
  229. let g:syntastic_auto_jump = 1
  230. """"""""" Vdebug
  231. let g:vdebug_options = {
  232. \ 'break_on_open' : 0,
  233. \ 'watch_window_style' : 'compact',
  234. \ 'path_maps' : {"/usr": "/jails/alcatraz/usr"}
  235. \ }
  236. """"""""" Supertab
  237. let g:SuperTabDefaultCompletionType = 'context'
  238. """"""""" Vim Markdown
  239. let g:vim_markdown_folding_disabled = 1
  240. """"""""" Remove completion omni in the event that it is too slow
  241. "let g:neocomplete#sources#omni#input_patterns = {}
  242. "let g:neocomplcache_omni_patterns = {}
  243. " Find merge conflict markers
  244. map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
  245. " Allow using the repeat operator with a visual selection (!)
  246. " http://stackoverflow.com/a/8064607/127816
  247. vnoremap . :normal .<CR>
  248. """"""""" Source local scripts/plugins
  249. for filePath in split(globpath('~/dotfiles/vim/settings', '*.vim'), '\n')
  250. execute 'source' filePath
  251. endfor