vimrc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. set nocompatible "Don't have to try to be compatible with old vi
  2. set encoding=utf-8
  3. """"""""
  4. "" Plugin Loading with Pathogen
  5. """""""""""""""""""""""""""""""""""""""""""""""""""
  6. call pathogen#infect()
  7. call pathogen#helptags()
  8. """"""""
  9. "" Environment
  10. """""""""""""""""""""""""""""""""""""""""""""""""""
  11. " Determine what kind of machine we're on e.g. Linux, Darwin, Win(?)
  12. if has("unix")
  13. " remove the newline character from the uname command
  14. let s:uname = substitute(system("uname"), "\n", "", "")
  15. endif
  16. """"""""
  17. "" General Behaviours
  18. """""""""""""""""""""""""""""""""""""""""""""""""""
  19. set splitbelow "New splits appear below current window instead of above
  20. set splitright "New splits appear right of current window
  21. set ttyfast "Smooth movement
  22. " Persistent undo
  23. if has("persistent_undo")
  24. set undofile
  25. set undodir=~/.vimundo
  26. endif
  27. set ttymouse=xterm2
  28. if has("autocmd")
  29. " Enable filetype specific features
  30. filetype plugin indent on
  31. " Clear existing autocmd
  32. autocmd!
  33. " When editing a file, always jump to the last cursor position
  34. autocmd BufReadPost *
  35. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  36. \ exe "normal! g'\"" |
  37. \ endif
  38. autocmd WinEnter * setlocal cursorline
  39. autocmd WinLeave * setlocal nocursorline
  40. " Show trailing white space
  41. autocmd InsertEnter * match ExtraWhitespace /\s\+\%#\@<!$/
  42. " Source the vimrc file after saving it
  43. autocmd bufwritepost .vimrc source $MYVIMRC
  44. " A way to specify startup actions
  45. autocmd VimEnter * call StartUp()
  46. " if the last window is NERDTree, then close Vim
  47. "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
  48. else
  49. set autoindent on
  50. endif
  51. """"""""
  52. "" Start Up
  53. """""""""""""""""""""""""""""""""""""""""""""""""""
  54. function! StartUp()
  55. " Stuff in here will be called by autocmd below
  56. " example, start NERDTree if vim called with no arguments
  57. if 0 == argc()
  58. NERDTree
  59. end
  60. endfunction
  61. """"""""
  62. "" Tabs and Text Formatting
  63. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  64. set expandtab " change to single spaces
  65. set tabstop=2 " actual tab press distance
  66. set shiftround " indent to nearest tabstops
  67. set shiftwidth=2 " amount to indent with > and <
  68. set smarttab " backspace tabs where appropriate even if spaces
  69. set softtabstop=2 " let backspace delete indent
  70. set wrap lbr " wrap long lines of text
  71. set backspace=eol,start,indent "backspace over everything
  72. set textwidth=80
  73. set colorcolumn=+1 " mark out the limits of the textwidth
  74. set listchars=trail:_,tab:>.,eol:$
  75. """"""""
  76. "" UI - Colours
  77. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  78. syntax enable
  79. colorscheme solarized
  80. set t_Co=16
  81. set background=dark
  82. " set colour for folded lines
  83. highlight Folded term=none cterm=none ctermfg=darkred ctermbg=none
  84. " show trailing white space
  85. highlight ExtraWhitespace ctermfg=red ctermbg=red guifg=red guibg=red
  86. """"""""
  87. "" UI - Numbering
  88. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  89. set number " show line numbers
  90. "set relativenumber " current line always 0 (requires 7.3 and up)
  91. """"""""
  92. "" UI - Statusline (now using powerline)
  93. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  94. set laststatus=2 " status line is second last line (not hidden by commands)
  95. """"""""
  96. "" UI - Code Folding
  97. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  98. set foldmethod=indent
  99. set foldlevel=10
  100. set foldtext=FoldText()
  101. """"""""
  102. "" UI - Search
  103. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  104. set hlsearch " make searches highlighted
  105. set incsearch " vim will search as you type!
  106. set ignorecase " ignore case for searches
  107. set smartcase " well, unless a user puts in uppercase search characters
  108. set magic " enables wildcard searching
  109. """"""""
  110. "" Key Remaps
  111. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  112. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  113. " More convenient escape
  114. imap ii <Esc>
  115. imap II <Esc>
  116. " Yank to end of line, like D
  117. nmap Y y$
  118. " Clear trailing white space
  119. nmap <silent> <leader>$ :%s/\s\+$//g<CR>
  120. " Add extra lines up and down
  121. nmap <leader>j o<Esc>k
  122. nmap <leader>k O<Esc>j
  123. " Edit .vimrc
  124. nmap <leader>v :e $MYVIMRC<CR>
  125. nmap <silent> <leader>n :set number!<CR>
  126. nmap <silent> <leader>w :set wrap!<CR>
  127. " Toggle paste mode - no autoindenting of pasted material
  128. nmap <silent> <leader>p :set paste! paste?<CR>
  129. " Toggle visible whitespace characters
  130. nmap <silent> <leader>l :set list!<CR>
  131. " Toggle scrollbind for moving multiple splits in sync together
  132. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  133. " Toggle mouse support.
  134. nmap <silent> <leader>m :call ToggleMouse()<CR>
  135. " Toggle NERDTree file browser
  136. nmap <silent> <leader>d :NERDTreeToggle<CR>
  137. " Toggle Commenting out lines with NERDCommenter
  138. nmap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  139. vmap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  140. " Traverse undo tree with Gundo!
  141. nmap <silent> <leader>u :GundoToggle<CR>
  142. " Git blame with Fugitive!
  143. nmap <silent> <leader>b :Gblame<CR>
  144. " Code heirarchy with Tagbar!
  145. nmap <silent> <leader>t :TagbarToggle<CR>
  146. """"""""
  147. "" Key Remaps - Movement and Windows
  148. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  149. " jump to beginning and end of line easier
  150. nmap H ^
  151. nmap L $
  152. " Smart way to move between windows
  153. nmap <C-j> <C-W>j
  154. nmap <C-k> <C-W>k
  155. nmap <C-h> <C-W>h
  156. nmap <C-l> <C-W>l
  157. " mapping to make movements operate on 1 screen line in wrap mode
  158. onoremap <silent> <expr> j ScreenMovement("j")
  159. onoremap <silent> <expr> k ScreenMovement("k")
  160. onoremap <silent> <expr> 0 ScreenMovement("0")
  161. onoremap <silent> <expr> ^ ScreenMovement("^")
  162. onoremap <silent> <expr> $ ScreenMovement("$")
  163. nnoremap <silent> <expr> j ScreenMovement("j")
  164. nnoremap <silent> <expr> k ScreenMovement("k")
  165. nnoremap <silent> <expr> 0 ScreenMovement("0")
  166. nnoremap <silent> <expr> ^ ScreenMovement("^")
  167. nnoremap <silent> <expr> $ ScreenMovement("$")
  168. """"""""
  169. "" Plugin options
  170. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  171. """"""""" NERDTree
  172. let g:NERDTreeQuitOnOpen = 1
  173. if s:uname == "Darwin"
  174. let g:NERDTreeDirArrows=0 " Problems showing NERDTree arrows in OS X
  175. endif
  176. """"""""" Gundo
  177. let g:gundo_width = 30
  178. let g:gundo_preview_height = 12
  179. let g:gundo_preview_bottom = 1
  180. """"""""" Surround
  181. "let g:loaded_surround = 1 " Disable tpope's surround
  182. let g:did_surrounding = 1 " Disable msander's surrounding (surround fork)
  183. """"""""" HTML Autoclose Tag
  184. " We are instead trying out sparkup
  185. let g:mapped_auto_closetag = 1 " Disable html autoclose plugin
  186. let g:did_auto_closetag = 1 " Disable html autoclose plugin
  187. """"""""" Powerline
  188. let g:Powerline_symbols = 'compatible' " alternatives: fancy, unicode
  189. """"""""" Tagbar
  190. let g:tagbar_autoclose = 1
  191. """"""""
  192. "" Functions, the Givers of Power (in order of use)
  193. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  194. function! FoldText()
  195. let line = getline(v:foldstart)
  196. let indent = indent(v:foldstart)
  197. let indentOnly = strpart(line, 0, indent-1)
  198. let linecount = v:foldend+1 - v:foldstart
  199. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  200. return foldtext
  201. endfunction
  202. function! ToggleMouse()
  203. if &mouse == 'a'
  204. set mouse=
  205. echo "Mouse usage disabled"
  206. else
  207. set mouse=a
  208. echo "Mouse usage enabled"
  209. endif
  210. endfunction
  211. function! ScreenMovement(movement)
  212. if &wrap
  213. return "g" . a:movement
  214. else
  215. return a:movement
  216. endif
  217. endfunction