vimrc 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  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. " Source the vimrc file after saving it
  41. autocmd bufwritepost .vimrc source $MYVIMRC
  42. " A way to specify startup actions
  43. autocmd VimEnter * call StartUp()
  44. " if the last window is NERDTree, then close Vim
  45. "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
  46. else
  47. set autoindent on
  48. endif
  49. """"""""
  50. "" Start Up
  51. """""""""""""""""""""""""""""""""""""""""""""""""""
  52. function! StartUp()
  53. " Stuff in here will be called by autocmd below
  54. " example, start NERDTree if vim called with no arguments
  55. if 0 == argc()
  56. NERDTree
  57. end
  58. endfunction
  59. """"""""
  60. "" Tabs and Text Formatting
  61. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  62. set expandtab " change to single spaces
  63. set tabstop=2 " actual tab press distance
  64. set shiftround " indent to nearest tabstops
  65. set shiftwidth=2 " amount to indent with > and <
  66. set smarttab " backspace tabs where appropriate even if spaces
  67. set softtabstop=2 " let backspace delete indent
  68. set wrap lbr " wrap long lines of text
  69. set backspace=eol,start,indent "backspace over everything
  70. set textwidth=80
  71. set colorcolumn=+1 " mark out the limits of the textwidth
  72. """"""""
  73. "" UI - Colours
  74. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  75. syntax enable
  76. colorscheme solarized
  77. set t_Co=16
  78. set background=dark
  79. hi Folded term=none cterm=none ctermfg=darkred ctermbg=none "set colour for folded lines
  80. """"""""
  81. "" UI - Numbering
  82. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  83. set number " show line numbers
  84. "set relativenumber " current line always 0 (requires 7.3 and up)
  85. """"""""
  86. "" UI - Statusline (now using powerline)
  87. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  88. set laststatus=2 " status line is second last line (not hidden by commands)
  89. """"""""
  90. "" UI - Code Folding
  91. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  92. set foldmethod=indent
  93. set foldlevel=10
  94. set foldtext=FoldText()
  95. """"""""
  96. "" UI - Search
  97. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  98. set hlsearch " make searches highlighted
  99. set incsearch " vim will search as you type!
  100. set ignorecase " ignore case for searches
  101. set smartcase " well, unless a user puts in uppercase search characters
  102. set magic " enables wildcard searching
  103. """"""""
  104. "" Key Remaps and Shortcuts
  105. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  106. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  107. " Edit .vimrc
  108. map <leader>v :e $MYVIMRC<CR>
  109. " More convenient escape
  110. imap ii <Esc>
  111. imap II <Esc>
  112. " Add extra lines up and down
  113. nmap <leader>j o<Esc>k
  114. nmap <leader>k O<Esc>j
  115. nmap <silent> <leader>n :set number!<CR>
  116. nmap <silent> <leader>w :set wrap!<CR>
  117. " Toggle paste mode - no autoindenting of pasted material
  118. nmap <silent> <leader>p :set paste! paste?<CR>
  119. " Toggle visible whitespace characters
  120. nmap <silent> <leader>l :set list!<CR>
  121. " Toggle scrollbind for moving multiple splits in sync together
  122. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  123. " Toggle mouse support.
  124. nnoremap <leader>m :call ToggleMouse()<CR>
  125. " Toggle NERDTree file browser
  126. nnoremap <silent> <leader>d :NERDTreeToggle<CR>
  127. " Toggle Commenting out lines with NERDCommenter
  128. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  129. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  130. " Traverse undo tree with Gundo!
  131. nnoremap <leader>u :GundoToggle<CR>
  132. " Git blame with Fugitive!
  133. nnoremap <leader>b :Gblame<CR>
  134. " Code heirarchy with Tagbar!
  135. nnoremap <leader>t :TagbarToggle<CR>
  136. """"""""
  137. "" Key Remaps - Movement and Windows
  138. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  139. " jump to beginning and end of line easier
  140. nmap H ^
  141. nmap L $
  142. " Smart way to move between windows
  143. nmap <C-j> <C-W>j
  144. nmap <C-k> <C-W>k
  145. nmap <C-h> <C-W>h
  146. nmap <C-l> <C-W>l
  147. " mapping to make movements operate on 1 screen line in wrap mode
  148. onoremap <silent> <expr> j ScreenMovement("j")
  149. onoremap <silent> <expr> k ScreenMovement("k")
  150. onoremap <silent> <expr> 0 ScreenMovement("0")
  151. onoremap <silent> <expr> ^ ScreenMovement("^")
  152. onoremap <silent> <expr> $ ScreenMovement("$")
  153. nnoremap <silent> <expr> j ScreenMovement("j")
  154. nnoremap <silent> <expr> k ScreenMovement("k")
  155. nnoremap <silent> <expr> 0 ScreenMovement("0")
  156. nnoremap <silent> <expr> ^ ScreenMovement("^")
  157. nnoremap <silent> <expr> $ ScreenMovement("$")
  158. """"""""
  159. "" Plugin options
  160. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  161. """"""""" NERDTree
  162. let g:NERDTreeQuitOnOpen = 1
  163. if s:uname == "Darwin"
  164. let g:NERDTreeDirArrows=0 " Problems showing NERDTree arrows in OS X
  165. endif
  166. """"""""" Gundo
  167. let g:gundo_width = 30
  168. let g:gundo_preview_height = 12
  169. let g:gundo_preview_bottom = 1
  170. """"""""" Surround
  171. "let g:loaded_surround = 1 " Disable tpope's surround
  172. let g:did_surrounding = 1 " Disable msander's surrounding (surround fork)
  173. """"""""" HTML Autoclose Tag
  174. " We are instead trying out sparkup
  175. let g:mapped_auto_closetag = 1 " Disable html autoclose plugin
  176. let g:did_auto_closetag = 1 " Disable html autoclose plugin
  177. """"""""" Powerline
  178. let g:Powerline_symbols = 'compatible'
  179. """"""""
  180. "" Functions, the Givers of Power (in order of use)
  181. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  182. function! FoldText()
  183. let line = getline(v:foldstart)
  184. let indent = indent(v:foldstart)
  185. let indentOnly = strpart(line, 0, indent-1)
  186. let linecount = v:foldend+1 - v:foldstart
  187. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  188. return foldtext
  189. endfunction
  190. function! ToggleMouse()
  191. if &mouse == 'a'
  192. set mouse=
  193. echo "Mouse usage disabled"
  194. else
  195. set mouse=a
  196. echo "Mouse usage enabled"
  197. endif
  198. endfunction
  199. function! ScreenMovement(movement)
  200. if &wrap
  201. return "g" . a:movement
  202. else
  203. return a:movement
  204. endif
  205. endfunction
  206. """"""""
  207. "" Graveyard
  208. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  209. "Old statusline options
  210. "set statusline=%f\ " short filepath
  211. "set statusline+=%h " help flag
  212. "set statusline+=%w " preview flag
  213. "set statusline+=%r " read-only flag
  214. "set statusline+=%m " modified flag
  215. "set statusline+=%= " left-right aligned item separator
  216. ""set statusline+=Chr:%B/%b " character value under cursor
  217. "set statusline+=%{fugitive#statusline()}
  218. "if exists("*strftime")
  219. "set statusline+=\ \ %{strftime('%a\ %d\ %b\ %H:%M')}
  220. "endif
  221. "set statusline+=\ \ %-14(Line:%l/%L%)
  222. "set statusline+=%-11(Col:%c%V%)
  223. "set statusline+=Scroll:%P
  224. " Colemak layout for INSERT mode only
  225. " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./
  226. " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./
  227. "inoremap <silent> e f
  228. "inoremap <silent> r p
  229. "inoremap <silent> t g
  230. "inoremap <silent> y j
  231. "inoremap <silent> u l
  232. "inoremap <silent> i u
  233. "inoremap <silent> o y
  234. "inoremap <silent> p ;
  235. "inoremap <silent> s r
  236. "inoremap <silent> d s
  237. "inoremap <silent> f t
  238. "inoremap <silent> g d
  239. "inoremap <silent> j n
  240. "inoremap <silent> k e
  241. "inoremap <silent> l i
  242. "inoremap <silent> ; o
  243. "inoremap <silent> n k
  244. "inoremap <silent> E F
  245. "inoremap <silent> R P
  246. "inoremap <silent> T G
  247. "inoremap <silent> Y J
  248. "inoremap <silent> U L
  249. "inoremap <silent> I U
  250. "inoremap <silent> O Y
  251. "inoremap <silent> P :
  252. "inoremap <silent> S R
  253. "inoremap <silent> D S
  254. "inoremap <silent> F T
  255. "inoremap <silent> G D
  256. "inoremap <silent> J N
  257. "inoremap <silent> K E
  258. "inoremap <silent> L I
  259. "inoremap <silent> : O
  260. "inoremap <silent> N K