vimrc 7.0 KB

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