vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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. " New window split settings
  39. set splitright
  40. """""""""""""""""""""""""""""""""""""""""
  41. " Keybinds
  42. """""""""""""""""""""""""""""""""""""""""
  43. let mapleader="\<space>"
  44. " Wrapped lines treated like normal ones
  45. nnoremap j gj
  46. nnoremap k gk
  47. " Set CTRL+S to save becuase I smack that every 10 seconds on whatever application I use
  48. " browse is only available in gvim
  49. command -nargs=0 -bar Update if &modified
  50. \| if empty(bufname('%'))
  51. \| browse confirm write
  52. \| else
  53. \| confirm write
  54. \| endif
  55. \| endif
  56. nnoremap <silent> <C-s> :Update<CR>
  57. inoremap <C-s> <C-o>:Update<CR>
  58. vnoremap <C-s> <C-o>:Update<CR>
  59. " CTRL+w to close the current buffer
  60. nnoremap <silent> <C-w> :call CloseWindow()<CR>
  61. " Buffer magic
  62. nnoremap <leader>l :ls<CR>:b<space>
  63. " Switch indentation settings
  64. nnoremap <leader>y :set expandtab tabstop=4 shiftwidth=4 softtabstop=4<CR>
  65. nnoremap <leader>Y :set expandtab tabstop=8 shiftwidth=8 softtabstop=4<CR>
  66. nnoremap <leader>m :set expandtab tabstop=2 shiftwidth=2 softtabstop=2<CR>
  67. nnoremap <leader>M :set noexpandtab tabstop=8 softtabstop=4 shiftwidth=4<CR>
  68. " To wrap or not to wrap
  69. nnoremap <leader>w :setlocal wrap!<CR>:setlocal wrap?<CR>
  70. " Window Switching and Resizing
  71. nnoremap <silent> <C-k> :wincmd k<CR>
  72. nnoremap <silent> <C-J> :wincmd j<CR>
  73. nnoremap <silent> <C-h> :wincmd h<CR>
  74. nnoremap <silent> <C-l> :wincmd l<CR>
  75. nnoremap <silent> + :wincmd +<CR>
  76. nnoremap <silent> _ :wincmd -<CR>
  77. nnoremap <silent> ) :wincmd ><CR>
  78. nnoremap <silent> ( :wincmd <<CR>
  79. nnoremap <silent> <leader>r :wincmd r<CR>
  80. nnoremap <silent> <leader>R :wincmd R<CR>
  81. " Ctrl+d to duplicate a line, vmode versions is best for SHIFT+V, not the others
  82. nnoremap <C-d> yyp
  83. vnoremap <C-d> y<C-o>p
  84. inoremap <C-d> <C-o>:yank<CR><C-o>:put<CR>
  85. " Open new files in new buffer or new windows
  86. nnoremap <C-o> :e<space>
  87. nnoremap <C-p> :sp<space>
  88. nnoremap <A-p> :vs<space>
  89. " Move lines of text via Alt+[jk] (Like sublime!)
  90. nnoremap <A-j> :m+1<CR>==
  91. nnoremap <A-k> :m-2<CR>==
  92. vnoremap <A-j> :m '>+1<CR>gv=gv
  93. vnoremap <A-k> :m '<-2<CR>gv=gv
  94. " Clear searches so there aren't underlined words.
  95. nnoremap <silent> <C-i> :nohlsearch<CR>
  96. " Mapped keys for plugins, these are listed in respective plugin sections
  97. "<leader>e => Nerd Tree Toggle
  98. "<Leader>/ => NerdCommenterToggle
  99. "<leader>T => Tag List Toggle
  100. "<leader>o => CtrlP Toggle
  101. """""""""""""""""""""""""""""""""""""""""
  102. " Ctrl-P Settings
  103. """""""""""""""""""""""""""""""""""""""""
  104. " Keybinding and functionality
  105. let g:ctrlp_map = "<leader>o"
  106. let g:ctrlp_cmd = 'CtrlPLastMode'
  107. let g:ctrlp_extensions = ['line']
  108. " Move Ctrl-P to top of the screen
  109. let g:ctrlp_match_window_bottom = 0
  110. let g:ctrlp_match_window_reversed = 0
  111. " Ignore some filetypes
  112. let g:ctrlp_custom_ignore = '\v\~$|\.(o|swp|pyc|wav|mp3|ogg|blend)$|(^|[/\\])\.(hg|git|bzr)($|[/\\])|__init__\.py'
  113. let g:ctrlp_switch_buffer = 'E'
  114. "let g:ctrlp_by_filename = 1
  115. let g:ctrlp_clear_cache_on_exit = 0
  116. " Uncomment to show hidden directories.
  117. "let g:ctrlp_show_hidden = 1
  118. """""""""""""""""""""""""""""""""""""""""
  119. " NerdTree
  120. """""""""""""""""""""""""""""""""""""""""
  121. " Directory tree toggle
  122. nnoremap <leader>e :NERDTreeToggle<CR>
  123. """""""""""""""""""""""""""""""""""""""""
  124. " NerdCommenter
  125. """""""""""""""""""""""""""""""""""""""""
  126. map <leader>cc <plug>NERDCommenterToggle
  127. " For some reason, CommentToggle doesn't work unless this is
  128. " remapped, so remapping it to something I won't ever use.
  129. map <leader><A-/><space> <plug>NERDCommenterComment
  130. " Not sure if I want default c prefix or a different one.
  131. " Note : Insert is disabled by default
  132. "map <leader>/c\<space> <plug>NERDCommenterComment
  133. "map <leader>/n <plug>NERDCommenterNested
  134. "map <leader>/\<space> <plug>NERDCommenterToggle
  135. "map <leader>/m <plug>NERDCommenterMinimal
  136. "map <leader>/i <plug>NERDCommenterInvert
  137. "map <leader>/s <plug>NERDCommenterSexy
  138. "map <leader>/y <plug>NERDCommenterYank
  139. "map <leader>/$ <plug>NERDCommenterToEOL
  140. "map <leader>/A <plug>NERDCommenterAppend
  141. ""map <leader>/ <plug>NERDCommenterInsert
  142. "map <leader>/a <plug>NERDCommenterAltDelims
  143. "map <leader>/b <plug>NERDCommenterAlignLeft
  144. "map <leader>/l <plug>NERDCommenterAlignBoth
  145. "map <leader>/u <plug>NERDCommenterUncomment
  146. """"""""""""""""""""""""""""""""""""""""
  147. " YouCompleteMe
  148. """"""""""""""""""""""""""""""""""""""""
  149. " Unbind tab so as not to interfere with Ultisnips
  150. let g:ycm_key_list_select_completion = ['<Tab>']
  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