Guest User

Vimrc

a guest
Jan 8th, 2013
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VIM 16.78 KB | None | 0 0
  1. set nocompatible                " Default to Vim instead of Vi
  2. filetype off                    " required!
  3.  
  4. set rtp+=~/.vim/bundle/vundle/
  5. call vundle#rc()
  6.  
  7. " let Vundle manage Vundle. Required!
  8. Bundle 'gmarik/vundle'
  9.  
  10. " Navigation.
  11. Bundle 'ZoomWin'
  12. Bundle 'Lokaltog/vim-easymotion'
  13. Bundle 'kien/ctrlp.vim'
  14.  
  15. " UI enhancements.
  16. Bundle 'mutewinter/vim-indent-guides'
  17. Bundle 'Lokaltog/vim-powerline'
  18. Bundle 'tomtom/quickfixsigns_vim'
  19. Bundle 'myusuf3/numbers.vim'
  20. Bundle 'majutsushi/tagbar'
  21. Bundle 'altercation/vim-colors-solarized'
  22. Bundle 'Mustang2'
  23.  
  24. " Commands
  25. Bundle 'scrooloose/nerdcommenter'
  26. Bundle 'tpope/vim-surround'
  27. Bundle 'tpope/vim-fugitive'
  28. Bundle 'tpope/vim-repeat'
  29. Bundle 'tpope/vim-unimpaired'
  30. Bundle 'godlygeek/tabular'
  31. Bundle 'mileszs/ack.vim'
  32. Bundle 'milkypostman/vim-togglelist'
  33. Bundle 'keepcase.vim'
  34. Bundle 'scratch.vim'
  35. Bundle 'tpope/vim-eunuch'
  36. Bundle 'HelpClose'
  37. Bundle 'mattn/gist-vim'
  38. Bundle 'Shougo/neocomplcache'
  39. Bundle 'sjl/gundo.vim'
  40. Bundle 'YankRing.vim'
  41.  
  42. " Helpers
  43. Bundle 'IndexedSearch'
  44. Bundle 'Raimondi/delimitMate'
  45. Bundle 'scrooloose/syntastic'
  46. Bundle 'ervandew/supertab'
  47.  
  48. " Libraries
  49. Bundle 'L9'
  50. Bundle 'tpope/vim-repeat'
  51. Bundle 'mattn/webapi-vim'
  52.  
  53. " HTML
  54. Bundle 'gregsexton/MatchTag'
  55. Bundle 'othree/html5.vim'
  56. Bundle 'indenthtml.vim'
  57.  
  58. " Markdown
  59. Bundle 'tpope/vim-markdown'
  60.  
  61.  
  62. " ----------------------------------------
  63. " Bindings
  64. " ----------------------------------------
  65.  
  66. " Set leader to ,
  67. " Note: This line MUST come before any <leader> mappings
  68. let mapleader=","
  69.  
  70. " Fixes common typos
  71. command! W w
  72. command! Q q
  73. map <F1> <Esc>
  74. imap <F1> <Esc>
  75.  
  76. vnoremap <F1> <Esc>:w<CR>
  77. nnoremap <F1> <Esc>:w<CR>
  78. inoremap <F1> <Esc>:w<CR>
  79. inoremap <F2> <Esc>:w<CR>
  80. nnoremap <F2> <Esc>:w<CR>
  81. vnoremap <F2> <Esc>:w<CR>
  82.  
  83. nnoremap <Left> :bp<CR>
  84. nnoremap <Right> :bn<CR>
  85.  
  86.  
  87.  
  88. " Crazy flying pinky
  89. cnoremap w' w<CR>
  90. " This mapping along with mapping ; to : allows for quick save with ;w;
  91. cnoremap w; w<CR>
  92. " Disable the ever-annoying Ex mode shortcut key. Type visual my ass. Make it
  93. " repeat the last macro instead. *hat tip* http://vimbits.com/bits/263
  94. nmap Q @@
  95.  
  96. " Removes doc lookup binding because it's easy to fat finger
  97. nmap K k
  98. vmap K k
  99.  
  100. " Make line completion easier
  101. imap <C-l> <C-x><C-l>
  102.  
  103. " Easier Scrolling (think j/k with left hand)
  104. " All variations are mapped for now until I get used to one
  105. " C/M/D + d (page up)
  106. " C/M/D + f (page down)
  107. nmap <C-d> <C-b>
  108. if has("gui_macvim")
  109.   nmap <D-f> <C-f>
  110.   nmap <D-d> <C-b>
  111. else
  112.   nmap <M-f> <C-f>
  113.   nmap <M-d> <C-b>
  114. endif
  115.  
  116. " Overrides neocomplcache with regular keyword completion
  117. inoremap <expr><C-k> "\<C-x><C-n>"
  118.  
  119. " Use ; for : in normal and visual mode, less keystrokes
  120. nnoremap ; :
  121. vnoremap ; :
  122. " double percentage sign in command mode is expanded
  123. " to directory of current file - http://vimcasts.org/e/14
  124. cnoremap %% <C-R>=expand('%:h').'/'<cr>
  125.  
  126. " Yank entire buffer with gy
  127. nmap gy :%y+<cr>
  128.  
  129. " Make Y behave like other capital commands.
  130. " Hat-tip http://vimbits.com/bits/11
  131. nnoremap Y y$
  132.  
  133. " Just to beginning and end of lines easier. From http://vimbits.com/bits/16
  134. noremap H ^
  135. noremap L $
  136.  
  137. " Clear search
  138. map <silent><Leader>/ :nohls<CR>
  139.  
  140. " Highlight search word under cursor without jumping to next
  141. nnoremap <leader>h *<C-O>
  142.  
  143. " ---------------
  144. " Leader Commands
  145. " ---------------
  146.  
  147. " Toggle spelling mode with ,s
  148. nmap <silent> <leader>s :set spell!<CR>
  149. " Edit vimrc with ,v
  150. nmap <silent> <leader>v :e ~/.vim/vimrc<CR>
  151. " Quickly switch to last buffer
  152. nnoremap <leader>, :e#<CR>
  153.  
  154. " Window Movement
  155. " Here's a visual guide for moving between window splits.
  156. " 4 Window Splits
  157. " --------
  158. " g1 | g2
  159. " ---|----
  160. " g3 | g4
  161. " -------
  162. "
  163. " 6 Window Splits
  164. " -------------
  165. " g1 | gt | g2
  166. " ---|----|----
  167. " g3 | gb | g4
  168. " -------------
  169. nmap <silent> gh :wincmd h<CR>
  170. nmap <silent> gj :wincmd j<CR>
  171. nmap <silent> gk :wincmd k<CR>
  172. nmap <silent> gl :wincmd l<CR>
  173. " Upper left window
  174. nmap <silent> g1 :wincmd t<CR>
  175. " Upper right window
  176. nmap <silent> g2 :wincmd b<Bar>:wincmd k<CR>
  177. " Lower left window
  178. nmap <silent> g3 :wincmd t<Bar>:wincmd j<CR>
  179. " Lower right window
  180. nmap <silent> g4 :wincmd b<CR>
  181.  
  182. " Top Middle
  183. nmap <silent> gt g2<Bar>:wincmd h<CR>
  184. " Bottom Middle
  185. nmap <silent> gb g3<Bar>:wincmd l<CR>
  186.  
  187. " Previous Window
  188. nmap <silent> gp :wincmd p<CR>
  189. " Equal Size Windows
  190. nmap <silent> g= :wincmd =<CR>
  191. " Swap Windows
  192. nmap <silent> gx :wincmd x<CR>
  193.  
  194. " Window Splitting
  195. nmap <silent> <leader>hs :split<CR>
  196. nmap <silent> <leader>vs :vsplit<CR>
  197. " Close the current window
  198. nmap <silent> <leader>sc :close<CR>
  199.  
  200. " -----------------------
  201. " Escape / Write Bindings
  202. " -----------------------
  203.  
  204. " Let's make escape better, together.
  205. inoremap jj <Esc>
  206.  
  207. " Strip trailing spaces
  208. " nnoremap <leader>S :%s/\s\+$//<cr>:let @/=''<CR>
  209.  
  210. " -------------------------------------
  211. " The following commands are from Janus
  212. " http://git.io/_GhulA
  213. " -------------------------------------
  214.  
  215. " Underline the current line with '='
  216. nmap <silent> <leader>ul :t.\|s/./-/g\|:nohls<cr>
  217.  
  218. " Format the entire file
  219. nmap <leader>fef ggVG=
  220.  
  221. " Wrap the current line
  222. nmap <leader>fw Vgq
  223.  
  224.  
  225. "-----------------------------------------------------------------------------
  226. " Core Vim configuration - plugins independent
  227. "-----------------------------------------------------------------------------
  228.  
  229. " Behaviors ------------------------------------------------------------------
  230. syntax enable
  231. "set autoread                           " Automatically reload changes if detected
  232. set wildmenu                            " Turn on WiLd menu
  233. set hidden                              " Change buffer - without saving
  234. set history=768                         " Number of things to remember in history.
  235. set cf                                  " Enable error files & error jumping.
  236. set clipboard=unnamed                 " Yanks go on clipboard instead.
  237. "set autowrite                          " Writes on make/shell commands
  238. set timeoutlen=450                      " Time to wait for a command (after leader for example).
  239. set nostartofline                       " Don't go to the start of the line after some commands
  240. set scrolloff=7                         " Keep three lines below the last line when scrolling
  241. set encoding=utf-8                      " utf-8 as default encoding
  242. set fileformats=unix,dos,mac            " Prefer unix file format
  243.  
  244. " Colors ---------------------------------------------------------------------
  245. set t_Co=256                            " Convince vim it can use 256 colors
  246.  
  247. " Preferably solarized configurations should be in plugins_config.vim, but
  248. " they need to be set before setting the solarized colorscheme
  249. let g:solarized_termtrans=1
  250. let g:solarized_termcolors=256
  251. let g:solarized_contrast="high"
  252. let g:solarized_visibility="high"
  253.  
  254. set background=dark
  255. colorscheme solarized
  256. call togglebg#map("<F5>")
  257.  
  258. " Backups, swap files, and other annoying stuff - GTFO!
  259. set noswapfile
  260. set nobackup
  261. set nowritebackup
  262. set novisualbell
  263. set noerrorbells
  264.  
  265. " User Interface
  266. set ruler                               " Ruler on
  267. set number                              " Line numbers on
  268. set nowrap                              " Line wrapping off
  269. set laststatus=2                        " Always show the statusline
  270. set cmdheight=2                         " Make the command area two lines high
  271. set encoding=utf-8
  272.  
  273. set noshowmode                          " Don't show the mode since Powerline
  274.                                         " shows it
  275.  
  276. set title                               " Set the title of the window in the
  277.                                         " terminal to the file
  278.  
  279. if exists('+colorcolumn')               " Color the 80th column differently
  280.   set colorcolumn=80                    " as a wrapping guide.
  281. endif
  282.  
  283. if exists('+ballooneval')               " Disable tooltips for hovering
  284.   set noballooneval                     " keywords in Vim.
  285.   set balloondelay=100000               " Set tooltip delay, just in case.
  286. endif
  287.  
  288.  
  289. " Tabs, spaces, linebreaks, and other invisible chars ------------------------
  290. set list
  291. set list listchars=tab:→\ ,trail:·,extends:❯,precedes: ",eol:¶
  292. set showbreak=↪
  293.  
  294.  
  295.  
  296. " Text Format ----------------------------------------------------------------
  297. set tabstop=4
  298. " set backspace=4                         " Delete everything with backspace
  299. set shiftwidth=4                        " Tabs under smart indent
  300. set cindent
  301. set autoindent
  302. set smarttab
  303. set expandtab
  304.  
  305. " Searching ------------------------------------------------------------------
  306. set ignorecase                          " Case insensitive search
  307. set smartcase                           " Non-case sensitive search
  308. set incsearch
  309. set hlsearch
  310. set wildignore+=*.o,*.obj,*.exe,*.so,*.dll,*.pyc,.svn,.hg,.bzr,.git,
  311.   \.sass-cache,*.class,*.scssc,*.cssc,sprockets%*,*.lessc,*.gif,*.jpg,*.png
  312.  
  313. " Visual ---------------------------------------------------------------------
  314. set showmatch                           " Show matching brackets.
  315. set matchtime=2                         " How many tenths of a second to blink
  316.  
  317.  
  318. " Sounds ---------------------------------------------------------------------
  319. set noerrorbells
  320. set novisualbell
  321. set t_vb=
  322.  
  323. " Mouse ----------------------------------------------------------------------
  324. set mousehide                           " Hide mouse after chars typed
  325. set mouse=a                             " Mouse in all modes
  326.  
  327. " Better complete options to speed it up
  328. set complete=.,w,b,u,U
  329.  
  330.  
  331. " ----------------------------------------------------------------------------
  332. " Plugin specific configuration
  333. " ----------------------------------------------------------------------------
  334.  
  335. " Tagbar -------------------------------------------------------------------
  336. inoremap <F8> :TagbarToggle<CR>
  337. vnoremap <F8> :TagbarToggle<CR>
  338. nnoremap <F8> :TagbarToggle<CR>
  339.  
  340. " Numbers ------------------------------------------------------------------
  341. nnoremap <F10> :NumbersToggle<CR>
  342. vnoremap <F10> :NumbersToggle<CR>
  343.  
  344. " Neocachecompl --------------------------------------------------------------
  345. let g:neocomplcache_enable_at_startup=1
  346. let g:neocomplcache_enable_cursor_hold_i=1
  347. let g:neocomplcache_cursor_hold_i_time=200
  348. let g:neocomplcache_auto_completion_start_length=1
  349.  
  350. " Tab / Shift-Tab to cycle completions
  351. inoremap <expr><TAB>  pumvisible() ? "\<C-n>" : "\<TAB>"
  352. inoremap <expr><S-TAB>  pumvisible() ? "\<C-p>" : "\<S-TAB>"
  353.  
  354. " Required to make neocomplcache_cursor_hold_i_time work
  355. " See https://github.com/Shougo/neocomplcache/issues/140
  356. let s:update_time_save = &updatetime
  357. autocmd InsertEnter * call s:on_insert_enter()
  358.  
  359. function! s:on_insert_enter()
  360.   if &updatetime > g:neocomplcache_cursor_hold_i_time
  361.     let s:update_time_save = &updatetime
  362.     let &updatetime = g:neocomplcache_cursor_hold_i_time
  363.   endif
  364. endfunction
  365.  
  366. autocmd InsertLeave * call s:on_insert_leave()
  367.  
  368. function! s:on_insert_leave()
  369.   if &updatetime < s:update_time_save
  370.     let &updatetime = s:update_time_save
  371.   endif
  372. endfunction
  373.  
  374. " Syntastic ------------------------------------------------------------------
  375. let g:syntastic_enable_signs=1
  376. let g:syntastic_auto_loc_list=1
  377.  
  378. " Platform-specific config files
  379. "if has('win32') || has('win64')
  380. "  let g:syntastic_jsl_conf=$HOME.'/.vim/config/windows/syntastic/jsl.conf'
  381. "  let g:syntastic_disabled_filetypes=['sh'] " Disable .sh on Windows
  382. "endif
  383.  
  384.  
  385. " Indent Guides --------------------------------------------------------------
  386. let g:indent_guides_enable_on_vim_startup=1
  387.  
  388. " Session --------------------------------------------------------------------
  389. let g:session_autosave=0
  390. let g:session_autoload=0
  391. nnoremap <leader>os :OpenSession<CR>
  392.  
  393. " SpeedDating ----------------------------------------------------------------
  394. "let g:speeddating_no_mappings=1 " Remove default mappings (C-a etc.)
  395. "nmap <silent><leader>dm <Plug>SpeedDatingDown
  396. "nmap <silent><leader>dp <Plug>SpeedDatingUp
  397. "nmap <silent><leader>dn <Plug>SpeedDatingNowUTC
  398.  
  399. " Tabular --------------------------------------------------------------------
  400. nmap <Leader>t= :Tabularize /=<CR>
  401. vmap <Leader>t= :Tabularize /=<CR>
  402. nmap <Leader>t: :Tabularize /:\zs<CR>
  403. vmap <Leader>t: :Tabularize /:\zs<CR>
  404. nmap <Leader>t, :Tabularize /,\zs<CR>
  405. vmap <Leader>t, :Tabularize /,\zs<CR>
  406. nmap <Leader>t> :Tabularize /=>\zs<CR>
  407. vmap <Leader>t> :Tabularize /=>\zs<CR>
  408. nmap <Leader>t- :Tabularize /-<CR>
  409. vmap <Leader>t- :Tabularize /-<CR>
  410. nmap <Leader>t" :Tabularize /"<CR>
  411. vmap <Leader>t" :Tabularize /"<CR>
  412.  
  413. " Fugitive -------------------------------------------------------------------
  414. nmap <Leader>gc :Gcommit -v<CR>
  415. nmap <Leader>gw :Gwrite<CR>
  416. nmap <Leader>gs :Gstatus<CR>
  417. nmap <Leader>gp :Git push<CR>
  418.  " Mnemonic, gu = Git Update
  419. nmap <Leader>gu :Git pull<CR>
  420. nmap <Leader>gd :Gdiff<CR>
  421. " Exit a diff by closing the diff window
  422. nmap <Leader>gx :wincmd h<CR>:q<CR>
  423.  
  424. " Zoomwin --------------------------------------------------------------------
  425. " Zoom Window to Full Size
  426. nmap <silent> <leader>wo :ZoomWin<CR>
  427.  
  428. " ctrlp.vim ------------------------------------------------------------------
  429. " Ensure Ctrl-P isn't bound by default
  430. let g:ctrlp_map = ''
  431.  
  432. " Ensure max height isn't too large. (for performance)
  433. let g:ctrlp_max_height = 10
  434.  
  435. " Leader Commands
  436. nnoremap <leader>o :CtrlPRoot<CR>
  437. nnoremap <leader>b :CtrlPBuffer<CR>
  438. nnoremap <leader>u :CtrlPCurFile<CR>
  439. nnoremap <leader>m :CtrlPMRUFiles<CR>
  440.  
  441. " Powerline ------------------------------------------------------------------
  442. " Keep ^B from showing on Windows in Powerline
  443. if has('win32') || has('win64')
  444.   let g:Powerline_symbols = 'compatible'
  445. elseif has('gui_macvim')
  446.   let g:Powerline_symbols = 'fancy'
  447. endif
  448. call Pl#Theme#InsertSegment('ws_marker', 'after', 'lineinfo')
  449.  
  450. " Abbreviate All of the Mode Names
  451. "let g:Powerline_mode_n = 'N'
  452. "let g:Powerline_mode_i = 'I'
  453. "let g:Powerline_mode_R = 'R'
  454. "let g:Powerline_mode_v = 'V'
  455. "let g:Powerline_mode_V = 'VL'
  456. "let g:Powerline_mode_cv = 'VB'
  457. "let g:Powerline_mode_s = 'S'
  458. "let g:Powerline_mode_S = 'SL'
  459. "let g:Powerline_mode_cs = 'SB'
  460.  
  461. " colorscheme tweaks ---------------------------------------------------------
  462. " Make cssAttrs (center, block, etc.) the same color as units
  463. hi! link cssAttr Constant
  464.  
  465. " Ack.vim --------------------------------------------------------------------
  466. nmap <silent> <leader>as :AckFromSearch<CR>
  467. " Highlight word at cursor and then Ack it.
  468. nnoremap <leader>H *<C-O>:AckFromSearch!<CR>
  469.  
  470. " surround.vim ---------------------------------------------------------------
  471. " Use # to get a variable interpolation (inside of a string)}
  472. " ysiw#   Wrap the token under the cursor in #{}
  473. " Thanks to http://git.io/_XqKzQ
  474. let g:surround_35  = "#{\r}"
  475.  
  476.  
  477.  
  478. " Markdown-Preview -----------------------------------------------------------
  479. "nmap <Leader>md :MarkdownPreview<CR>
  480. "vmap <Leader>md :MarkdownPreview<CR>
  481.  
  482.  
  483. " indenthtml -----------------------------------------------------------------
  484. " Setup indenthtml to propertly indent html. Without this, formatting doesn't
  485. " work on html.
  486. let g:html_indent_inctags = "html,body,head,tbody"
  487. let g:html_indent_script1 = "inc"
  488. let g:html_indent_style1 = "inc"
  489.  
  490. " vim-markdown
  491. let g:vim_markdown_folding_disabled=1
  492.  
  493. " Unconditional Paste --------------------------------------------------------
  494. "let g:UnconditionalPaste_NoDefaultMappings=1
  495. "nmap gcP <Plug>UnconditionalPasteCharBefore
  496. "nmap gcp <Plug>UnconditionalPasteCharAfter
  497.  
  498. " Vundle --------------------------------------------------------------------
  499. nmap <Leader>bi :BundleInstall<CR>
  500. nmap <Leader>bu :BundleInstall!<CR> " Because this also updates
  501. nmap <Leader>bc :BundleClean<CR>
  502.  
  503.  
  504.  
  505. " ----------------------------------------------------------------------------
  506. " Functions
  507. " ----------------------------------------------------------------------------
  508.  
  509.  
  510.  
  511. " Strip trailing spaces ------------------------------------------------------
  512.  
  513. " From http://vimbits.com/bits/377
  514. " Preserves/Saves the state, executes a command, and returns to the saved state
  515. function! Preserve(command)
  516. " Preparation: save last search, and cursor position.
  517.   let _s=@/
  518.   let l = line(".")
  519.   let c = col(".")
  520. " Do the business:
  521.   execute a:command
  522. " Clean up: restore previous search history, and cursor position
  523.   let @/=_s
  524.   call cursor(l, c)
  525. endfunction
  526. "strip all trailing white space
  527. command! StripTrailingWhiteSpace :call Preserve("%s/\\s\\+$//e")<CR>
  528. nmap <silent> <leader>S :StripTrailingWhiteSpace<CR>  
  529.  
  530. " Paste using Paste Mode -----------------------------------------------------
  531. "
  532. " Keeps indentation in source.
  533. function! PasteWithPasteMode()
  534.   if &paste
  535.     normal p
  536.   else
  537. " Enable paste mode and paste the text, then disable paste mode.
  538.     set paste
  539.     normal p
  540.     set nopaste
  541.   endif
  542. endfunction
  543.  
  544. command! PasteWithPasteMode call PasteWithPasteMode()
  545. nmap <silent> <leader>p :PasteWithPasteMode<CR>
Advertisement
Add Comment
Please, Sign In to add comment