vimrc 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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 modeline " Support vim modelines at the top of files
  77. "set wildmode=list:longest,full " Command <Tab> completion, list matches, then longest common part, then all.
  78. set whichwrap=b,s,h,l,<,>,[,] " Backspace and cursor keys wrap too
  79. set shortmess+=filmnrxoOtT " Abbrev. of messages (avoids 'hit enter')
  80. set scrolljump=5 " Lines to scroll when cursor leaves screen
  81. set scrolloff=3 " Minimum lines to keep above and below cursor
  82. set foldenable " Auto fold code
  83. set list
  84. set listchars=tab:›\ ,trail:•,extends:#,nbsp:. " Highlight problematic whitespace
  85. if has('persistent_undo')
  86. set undofile " So is persistent undo ...
  87. set undolevels=1000 " Maximum number of changes that can be undone
  88. set undoreload=10000 " Maximum number lines to save for undo on a buffer reload
  89. endif
  90. """"""""
  91. "" UI - Mouse & Cursor
  92. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  93. " The following two settings are related to how vim reacts to the incoming $TERM
  94. " value from either the terminal emulator (e.g. iTerm2) or tmux. In the best
  95. " case, both of these should be set to xterm-256color. This will result in vim
  96. " reacting with the settings below:
  97. "set ttymouse=xterm2 " Needed to allow mouse support to resize windows
  98. "set ttyfast " Allows for instantaneous refresh when using the mouse to select
  99. """"""""
  100. "" UI - Solarized Fix
  101. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  102. " Fix solarized scheme in spf13-vim. The config sets up to use the degraded
  103. " 256-color mode for sake of some terminal emulators? (see
  104. " https://github.com/spf13/spf13-vim/issues/113).
  105. "
  106. " These two lines Must come in this order or they won't work: number and fold
  107. " columns and cursor line come out brownish (dark scheme) or black (light
  108. " scheme).
  109. "let g:solarized_termcolors=16
  110. "set t_Co=16
  111. """"""""
  112. "" UI - Code Folding
  113. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  114. set foldmethod=indent
  115. set foldlevel=10
  116. """"""""
  117. "" Key Remaps
  118. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  119. let mapleader = ','
  120. " More convenient escape
  121. inoremap kj <ESC>
  122. inoremap jk <ESC>
  123. " Yank from the cursor to the end of the line, to be consistent with C and D.
  124. nnoremap Y y$
  125. " Add extra lines up and down
  126. nnoremap <leader>j o<Esc>k
  127. nnoremap <leader>k O<Esc>j
  128. " Convert tabs to spaces
  129. nnoremap <silent> <leader><TAB> :%s/<TAB>/ /g<CR>
  130. " Backspace to clear current search (and stop highlighting)
  131. nnoremap <silent> <backspace> :call ClearSearch()<CR>
  132. function! ClearSearch()
  133. if (@/ != "")
  134. let @/=""
  135. redraw
  136. endif
  137. endfunction
  138. nnoremap <silent> <leader>w :set wrap!<CR>
  139. " Toggle paste mode - no autoindenting of pasted material
  140. nnoremap <silent> <leader>p :set paste! paste?<CR>
  141. " Toggle visible whitespace characters
  142. nnoremap <silent> <leader>l :set list!<CR>
  143. " Toggle keyboard layout
  144. "nnoremap <silent> <leader><space> :call CycleKeymap()<CR>
  145. "function! CycleKeymap()
  146. "if has('keymap')
  147. "if (&keymap == '')
  148. "set keymap=colemak
  149. "echo 'Colemak keymap selected'
  150. "elseif (&keymap == 'colemak')
  151. "set keymap=dvorak
  152. "echo 'Dvorak keymap selected'
  153. "else
  154. "set keymap=
  155. "echo 'Qwerty keymap selected'
  156. "endif
  157. "else
  158. "echo 'Keymaps not supported'
  159. "endif
  160. "endfunction
  161. " Toggle scrollbind for moving multiple splits in sync together
  162. nnoremap <silent> <leader>sb :set scrollbind! scrollbind?<CR>
  163. " Toggle mouse support.
  164. nnoremap <silent> <leader>m :call ToggleMouse()<CR>
  165. function! ToggleMouse()
  166. if &mouse == 'a'
  167. set mouse=
  168. echo 'Mouse usage disabled'
  169. else
  170. set mouse=a
  171. echo 'Mouse usage enabled'
  172. endif
  173. endfunction
  174. " Toggle NERDTree file browser
  175. nnoremap <silent> <leader>d :NERDTreeMirrorToggle<CR>
  176. let g:NERDTreeIgnore=['\.pyc', '\~$', '\.swo$', '\.swp$', '\.git', '\.hg', '\.svn', '\.bzr']
  177. let g:NERDTreeChDirMode=0
  178. let g:NERDTreeQuitOnOpen=1
  179. let g:NERDTreeMouseMode=2
  180. let g:NERDTreeShowHidden=1
  181. let g:NERDTreeKeepTreeInNewTab=1
  182. " Toggle Commenting out lines with NERDCommenter
  183. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  184. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  185. " Git commands with Fugitive
  186. nnoremap <silent> <leader>gc :Gcommit -v<CR>
  187. nnoremap <silent> <leader>gl :Glog<CR><CR>
  188. nnoremap <silent> <leader>gap :Git add -p<CR>
  189. nnoremap <silent> <leader>gs :Gstatus<CR>
  190. nnoremap <silent> <leader>gd :Gdiff<CR>
  191. nnoremap <silent> <leader>gb :Gblame<CR>
  192. if has("autocmd")
  193. " Fugitive - Go up to previous tree object while exploring git tree with '..'
  194. autocmd User fugitive
  195. \ if fugitive#buffer().type() =~# '^\%(tree\|blob\)$' |
  196. \ nnoremap <buffer> .. :edit %:h<CR> |
  197. \ endif
  198. " Fugitive - Delete buffers when they are not active
  199. autocmd BufReadPost fugitive://* set bufhidden=delete
  200. endif
  201. " Gundo
  202. nnoremap <silent> <leader>u :GundoToggle<CR>
  203. " Tagbar
  204. nnoremap <silent> <leader>t :TagbarToggle<CR>
  205. """"""""" CtrlP
  206. " Function definition jumping with CtrlP's Funky plugin
  207. nnoremap <silent> <C-F> :CtrlPFunky<CR>
  208. "let g:ctrlp_working_path_mode = 'rw' let's try out ra
  209. let g:ctrlp_user_command = {
  210. \ 'types': {
  211. \ 1: ['.git', 'cd %s && git ls-files . --cached --exclude-standard --others'],
  212. \ 2: ['.hg', 'hg --cwd %s locate -I .'],
  213. \ },
  214. \ 'fallback': 'find %s -type f'
  215. \ }
  216. let g:ctrlp_extensions = ['funky']
  217. """"""""" Powerline
  218. set laststatus=2
  219. set rtp+=~/dotfiles/powerline/powerline/powerline/bindings/vim
  220. set noshowmode " don't show e.g. --INSERT-- since we're using powerline
  221. """"""""" Tagbar
  222. let g:tagbar_autoclose = 1 " close sidebar after we go to selection
  223. """"""""" Indent Guides
  224. let g:indent_guides_enable_on_vim_startup = 1
  225. let g:indent_guides_auto_colors = 0
  226. " reverse indent guides highlighting
  227. "highlight IndentGuidesOdd ctermbg=grey
  228. highlight IndentGuidesEven ctermbg=black
  229. """"""""" Syntastic
  230. let g:syntastic_auto_jump = 1
  231. """"""""" Vdebug
  232. let g:vdebug_options = {
  233. \ 'break_on_open' : 0,
  234. \ 'watch_window_style' : 'compact',
  235. \ 'path_maps' : {"/usr": "/jails/alcatraz/usr"}
  236. \ }
  237. """"""""" Supertab
  238. let g:SuperTabDefaultCompletionType = 'context'
  239. """"""""" Vim Markdown
  240. let g:vim_markdown_folding_disabled = 1
  241. """"""""" Remove completion omni in the event that it is too slow
  242. "let g:neocomplete#sources#omni#input_patterns = {}
  243. "let g:neocomplcache_omni_patterns = {}
  244. " Find merge conflict markers
  245. map <leader>fc /\v^[<\|=>]{7}( .*\|$)<CR>
  246. " Allow using the repeat operator with a visual selection (!)
  247. " http://stackoverflow.com/a/8064607/127816
  248. vnoremap . :normal .<CR>
  249. """"""""" Source local scripts/plugins
  250. for filePath in split(globpath('~/dotfiles/vim/settings', '*.vim'), '\n')
  251. execute 'source' filePath
  252. endfor