vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. " Use pathogen to load other plugins
  2. execute pathogen#infect()
  3. filetype plugin indent on
  4. """""""""""""""""""""""""""""""""""""""""
  5. " Some Basics
  6. """""""""""""""""""""""""""""""""""""""""
  7. "Note : vim-sensible does some of these settings already
  8. set encoding=utf-8
  9. " Search settings
  10. set incsearch
  11. set ignorecase
  12. set smartcase
  13. set hlsearch
  14. " Indentation and tab functionality
  15. set tabstop=4
  16. set shiftwidth=4
  17. set softtabstop=4
  18. set expandtab
  19. set autoindent
  20. set smarttab
  21. set smartindent
  22. " Code Folding
  23. set nofoldenable
  24. set foldmethod=indent
  25. set foldnestmax=10
  26. set viewoptions=cursor,folds,slash,unix
  27. " let g:skipview_files = ['*\.vim']
  28. " Line numbers
  29. set number
  30. " Line Wrapping
  31. set nowrap
  32. " Automatically update externally updated files
  33. set autoread
  34. " Command expiration
  35. set timeout
  36. set ttimeoutlen=50
  37. """""""""""""""""""""""""""""""""""""""""
  38. " Keybinds
  39. """""""""""""""""""""""""""""""""""""""""
  40. let mapleader="\<space>"
  41. " Wrapped lines treated like normal ones
  42. nnoremap j gj
  43. nnoremap k gk
  44. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  45. " browse is only available in gvim
  46. command -nargs=0 -bar Update if &modified
  47. \| if empty(bufname('%'))
  48. \| browse confirm write
  49. \| else
  50. \| confirm write
  51. \| endif
  52. \| endif
  53. nnoremap <silent> <C-s> :Update<CR>
  54. inoremap <C-s> <C-o>:Update<CR>
  55. vnoremap <C-s> <C-o>:Update<CR>
  56. " CTRL+w to close the current buffer
  57. nnoremap <silent> <C-w> :call CloseWindow()<CR>
  58. " Buffer magic
  59. nnoremap <leader>l :ls<CR>:b<space>
  60. " Switch indentation settings
  61. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  62. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  63. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  64. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  65. " To wrap or not to wrap
  66. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  67. " Window Switching and Resizing
  68. nnoremap <silent> <C-k> :wincmd k<CR>
  69. nnoremap <silent> <C-J> :wincmd j<CR>
  70. nnoremap <silent> <C-h> :wincmd h<CR>
  71. nnoremap <silent> <C-l> :wincmd l<CR>
  72. nnoremap <silent> <F10> :wincmd +<CR>
  73. nnoremap <silent> <F9> :wincmd -<CR>
  74. nnoremap <silent> <A-F10> :wincmd ><CR>
  75. nnoremap <silent> <A-F9> :wincmd <<CR>
  76. nnoremap <silent> <leader>r :wincmd r<CR>
  77. nnoremap <silent> <leader>R :wincmd R<CR>
  78. " Ctrl+d to duplicate a line, vmode versions is best for SHIFT+V, not the others
  79. nnoremap <C-d> yyp
  80. vnoremap <C-d> y<C-o>p
  81. inoremap <C-d> <C-o>:yank<CR><C-o>:put<CR>
  82. " Open new files in new buffer or new windows
  83. nnoremap <C-o> :e<space>
  84. nnoremap <C-p> :sp<space>
  85. nnoremap <A-p> :rightb vs<space>
  86. " Move lines of text via Alt+[jk] (Like sublime!)
  87. nnoremap <A-j> :m+1<CR>==
  88. nnoremap <A-k> :m-2<CR>==
  89. vnoremap <A-j> :m '>+1<CR>gv=gv
  90. vnoremap <A-k> :m '<-2<CR>gv=gv
  91. " Clear searches so there aren't underlined words.
  92. nnoremap <silent> <C-i> :nohlsearch<CR>
  93. " Mapped keys for plugins, these are listed in respective plugin sections
  94. "<leader>e => Nerd Tree Toggle
  95. "<Leader>/ => NerdCommenterToggle
  96. "<leader>T => Tag List Toggle
  97. "<leader>o => CtrlP Toggle
  98. """""""""""""""""""""""""""""""""""""""""
  99. " Ctrl-P Settings
  100. """""""""""""""""""""""""""""""""""""""""
  101. " Keybinding and functionality
  102. let g:ctrlp_map = "<leader>o"
  103. let g:ctrlp_cmd = 'CtrlPLastMode'
  104. let g:ctrlp_extensions = ['line']
  105. " Move Ctrl-P to top of the screen
  106. let g:ctrlp_match_window_bottom = 0
  107. let g:ctrlp_match_window_reversed = 0
  108. " Ignore some filetypes
  109. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  110. let g:ctrlp_switch_buffer = 'E'
  111. "let g:ctrlp_by_filename = 1
  112. let g:ctrlp_clear_cache_on_exit = 0
  113. " Uncomment to show hidden directories.
  114. "let g:ctrlp_show_hidden = 1
  115. """""""""""""""""""""""""""""""""""""""""
  116. " NerdTree
  117. """""""""""""""""""""""""""""""""""""""""
  118. " Directory tree toggle
  119. nnoremap <leader>e :NERDTreeToggle<CR>
  120. """""""""""""""""""""""""""""""""""""""""
  121. " NerdCommenter
  122. """""""""""""""""""""""""""""""""""""""""
  123. map <leader>cc <plug>NERDCommenterToggle
  124. " For some reason, CommentToggle doesn't work unless this is
  125. " remapped, so remapping it to something I won't ever use.
  126. map <leader><A-/><space> <plug>NERDCommenterComment
  127. " Not sure if I want default c prefix or a different one.
  128. " Note : Insert is disabled by default
  129. "map <leader>/c\<space> <plug>NERDCommenterComment
  130. "map <leader>/n <plug>NERDCommenterNested
  131. "map <leader>/\<space> <plug>NERDCommenterToggle
  132. "map <leader>/m <plug>NERDCommenterMinimal
  133. "map <leader>/i <plug>NERDCommenterInvert
  134. "map <leader>/s <plug>NERDCommenterSexy
  135. "map <leader>/y <plug>NERDCommenterYank
  136. "map <leader>/$ <plug>NERDCommenterToEOL
  137. "map <leader>/A <plug>NERDCommenterAppend
  138. ""map <leader>/ <plug>NERDCommenterInsert
  139. "map <leader>/a <plug>NERDCommenterAltDelims
  140. "map <leader>/b <plug>NERDCommenterAlignLeft
  141. "map <leader>/l <plug>NERDCommenterAlignBoth
  142. "map <leader>/u <plug>NERDCommenterUncomment
  143. """"""""""""""""""""""""""""""""""""""""
  144. " Useful Stuff
  145. """"""""""""""""""""""""""""""""""""""""
  146. """"""""""""""""""""""""""""""""""""""""
  147. " YouCompleteMe
  148. """"""""""""""""""""""""""""""""""""""""
  149. " Unbind tab so as not to interfere with Ultisnips
  150. let g:ycm_key_list_select_completion = ['<Enter>']
  151. """""""""""""""""""""""""""""""""""""""""
  152. " TagList
  153. """""""""""""""""""""""""""""""""""""""""
  154. nnoremap <leader>t :TlistToggle<CR>
  155. """""""""""""""""""""""""""""""""""""""""
  156. " Easytags
  157. """""""""""""""""""""""""""""""""""""""""
  158. let g:easytags_updatetime_min = 2000
  159. """""""""""""""""""""""""""""""""""""""""
  160. " Tex Settings
  161. """""""""""""""""""""""""""""""""""""""""
  162. let g:tex_flavor = "latex"
  163. let g:LatexBox_latexmk_options = "-pvc -pdfps"
  164. autocmd FileType tex setlocal spell spelllang=en_us
  165. """""""""""""""""""""""""""""""""""""""""
  166. " Colors and Themes
  167. """""""""""""""""""""""""""""""""""""""""
  168. syntax enable
  169. "Set 256 color mode (not always needed).
  170. "if $TERM == "xterm-256color" || $TERM == "screen-256color" || $COLORTERM == "gnome-terminal"
  171. " set t_Co=256
  172. "endif
  173. " Use a nice color scheme
  174. colors Monokai
  175. """"""""""""""""""""""""""""""""""""""""
  176. " Useful Stuff
  177. """"""""""""""""""""""""""""""""""""""""
  178. " Return to last edit position on reopen
  179. autocmd BufReadPost *
  180. \ if line("'\"") > 0 && line("'\"") <= line("$") |
  181. \ exe "normal! g`\"" |
  182. \ endif
  183. " Remember buffer info on close
  184. set viminfo^=%
  185. " For Python/Coffeescript, delete trailing white space
  186. func! DeleteTrailingWS()
  187. exe "normal mz"
  188. %s/\s\+$//ge
  189. exe "normal `z"
  190. endfunc
  191. autocmd BufWrite *.py :call DeleteTrailingWS()
  192. autocmd BufWrite *.coffee :call DeleteTrailingWS()
  193. " Allow the use of ALT as a function key.
  194. let c='a'
  195. while c <= 'z'
  196. exec "set <A-".c.">=\e".c
  197. exec "imap \e".c." <A-".c.">"
  198. let c = nr2char(1+char2nr(c))
  199. endw
  200. " Close current window or vim if no unsaved windows are open.
  201. fun! CloseWindow()
  202. if &modified
  203. echo "Save first or manual exit."
  204. else
  205. if len(filter(range(1, bufnr('$')), 'buflisted(v:val)')) == 1
  206. q
  207. else
  208. :bd
  209. endif
  210. endif
  211. endfunction