vimrc 7.0 KB

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