vimrc 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. set nocompatible "Don't have to try to be compatible with old vi
  2. """"""""
  3. "" Plugin Loading with Pathogen
  4. """""""""""""""""""""""""""""""""""""""""""""""""""
  5. call pathogen#infect()
  6. """"""""
  7. "" Environment
  8. """""""""""""""""""""""""""""""""""""""""""""""""""
  9. " Determine what kind of machine we're on e.g. Linux, Darwin, Win(?)
  10. if has("unix")
  11. " remove the newline character from the uname command
  12. let s:uname = substitute(system("uname"), "\n", "", "")
  13. endif
  14. """"""""
  15. "" General Behaviours
  16. """""""""""""""""""""""""""""""""""""""""""""""""""
  17. set splitbelow "New splits appear below current window instead of above
  18. set splitright "New splits appear right of current window
  19. set ttyfast "Smooth movement
  20. " Persistent undo
  21. if has("persistent_undo")
  22. set undofile
  23. set undodir=~/.vimundo
  24. endif
  25. set ttymouse=xterm2
  26. if has("autocmd")
  27. " Enable filetype specific features
  28. filetype plugin indent on
  29. " Clear existing autocmd
  30. autocmd!
  31. " When editing a file, always jump to the last cursor position
  32. autocmd BufReadPost *
  33. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  34. \ exe "normal! g'\"" |
  35. \ endif
  36. autocmd WinEnter * setlocal cursorline
  37. autocmd WinLeave * setlocal nocursorline
  38. " Source the vimrc file after saving it
  39. autocmd bufwritepost .vimrc source $MYVIMRC
  40. " A way to specify startup actions
  41. autocmd VimEnter * call StartUp()
  42. " if the last window is NERDTree, then close Vim
  43. "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
  44. else
  45. set autoindent on
  46. endif
  47. """"""""
  48. "" Start Up
  49. """""""""""""""""""""""""""""""""""""""""""""""""""
  50. function! StartUp()
  51. " Stuff in here will be called by autocmd below
  52. " example, 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 indent
  66. set wrap lbr " wrap long lines of text
  67. set backspace=eol,start,indent "backspace over everything
  68. set textwidth=80
  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. hi Folded term=none cterm=none ctermfg=darkred ctermbg=none "set colour for folded lines
  78. """"""""
  79. "" UI - Numbering
  80. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  81. set number " show line numbers
  82. "set relativenumber " current line always 0 (requires 7.3 and up)
  83. set laststatus=2 " status line is second last line (not hidden by commands)
  84. set statusline=%f\ " short filepath
  85. set statusline+=%h " help flag
  86. set statusline+=%w " preview flag
  87. set statusline+=%r " read-only flag
  88. set statusline+=%m " modified flag
  89. set statusline+=%= " left-right aligned item separator
  90. "set statusline+=Chr:%B/%b " character value under cursor
  91. set statusline+=%{fugitive#statusline()}
  92. if exists("*strftime")
  93. set statusline+=\ \ %{strftime('%a\ %d\ %b\ %H:%M')}
  94. endif
  95. set statusline+=\ \ %-14(Line:%l/%L%)
  96. set statusline+=%-11(Col:%c%V%)
  97. set statusline+=Scroll:%P
  98. """"""""
  99. "" UI - Code Folding
  100. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  101. set foldmethod=indent
  102. set foldlevel=10
  103. set foldtext=FoldText()
  104. """"""""
  105. "" UI - Search
  106. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  107. set hlsearch " make searches highlighted
  108. set incsearch " vim will search as you type!
  109. set ignorecase " ignore case for searches
  110. set smartcase " well, unless a user puts in uppercase search characters
  111. set magic " enables wildcard searching
  112. """"""""
  113. "" Key Remaps and Shortcuts
  114. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  115. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  116. " Edit .vimrc
  117. map <leader>v :e $MYVIMRC<CR>
  118. " More convenient escape
  119. imap ii <Esc>
  120. imap II <Esc>
  121. " Add extra lines up and down
  122. nmap <leader>j o<Esc>k
  123. nmap <leader>k O<Esc>j
  124. nmap <silent> <leader>n :set number!<CR>
  125. nmap <silent> <leader>w :set wrap!<CR>
  126. " Toggle paste mode - no autoindenting of pasted material
  127. nmap <silent> <leader>p :set paste! paste?<CR>
  128. " Toggle visible whitespace characters
  129. nmap <silent> <leader>l :set list!<CR>
  130. " Toggle scrollbind for moving multiple splits in sync together
  131. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  132. " Toggle mouse support.
  133. nnoremap <leader>m :call ToggleMouse()<CR>
  134. " Toggle NERDTree file browser
  135. nnoremap <silent> <leader>d :NERDTreeToggle<CR>
  136. " Toggle Commenting out lines with NERDCommenter
  137. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  138. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  139. " Traverse undo tree with Gundo!
  140. nnoremap <leader>u :GundoToggle<CR>
  141. " Git blame with Fugitive!
  142. nnoremap <leader>b :Gblame<CR>
  143. """"""""
  144. "" Key Remaps - Movement and Windows
  145. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  146. " jump to beginning and end of line easier
  147. nmap H ^
  148. nmap L $
  149. " Smart way to move between windows
  150. nmap <C-j> <C-W>j
  151. nmap <C-k> <C-W>k
  152. nmap <C-h> <C-W>h
  153. nmap <C-l> <C-W>l
  154. " mapping to make movements operate on 1 screen line in wrap mode
  155. onoremap <silent> <expr> j ScreenMovement("j")
  156. onoremap <silent> <expr> k ScreenMovement("k")
  157. onoremap <silent> <expr> 0 ScreenMovement("0")
  158. onoremap <silent> <expr> ^ ScreenMovement("^")
  159. onoremap <silent> <expr> $ ScreenMovement("$")
  160. nnoremap <silent> <expr> j ScreenMovement("j")
  161. nnoremap <silent> <expr> k ScreenMovement("k")
  162. nnoremap <silent> <expr> 0 ScreenMovement("0")
  163. nnoremap <silent> <expr> ^ ScreenMovement("^")
  164. nnoremap <silent> <expr> $ ScreenMovement("$")
  165. """"""""
  166. "" Plugin options
  167. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  168. """"""""" NERDTree
  169. let g:NERDTreeQuitOnOpen = 1
  170. if s:uname == "Darwin"
  171. let g:NERDTreeDirArrows=0 " Problems showing NERDTree arrows in OS X
  172. endif
  173. """"""""" Gundo
  174. let g:gundo_width = 30
  175. let g:gundo_preview_height = 12
  176. let g:gundo_preview_bottom = 1
  177. """"""""" Surround
  178. "let g:loaded_surround = 1 " Disable tpope's surround
  179. let g:did_surrounding = 1 " Disable msander's surrounding (surround fork)
  180. """"""""" HTML Autoclose Tag
  181. " We are instead trying out sparkup
  182. let g:mapped_auto_closetag = 1 " Disable html autoclose plugin
  183. let g:did_auto_closetag = 1 " Disable html autoclose plugin
  184. """"""""
  185. "" Functions, the Givers of Power (in order of use)
  186. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  187. function! FoldText()
  188. let line = getline(v:foldstart)
  189. let indent = indent(v:foldstart)
  190. let indentOnly = strpart(line, 0, indent-1)
  191. let linecount = v:foldend+1 - v:foldstart
  192. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  193. return foldtext
  194. endfunction
  195. function! ToggleMouse()
  196. if &mouse == 'a'
  197. set mouse=
  198. echo "Mouse usage disabled"
  199. else
  200. set mouse=a
  201. echo "Mouse usage enabled"
  202. endif
  203. endfunction
  204. function! ScreenMovement(movement)
  205. if &wrap
  206. return "g" . a:movement
  207. else
  208. return a:movement
  209. endif
  210. endfunction
  211. " Colemak layout for INSERT mode only
  212. " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./
  213. " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./
  214. "inoremap <silent> e f
  215. "inoremap <silent> r p
  216. "inoremap <silent> t g
  217. "inoremap <silent> y j
  218. "inoremap <silent> u l
  219. "inoremap <silent> i u
  220. "inoremap <silent> o y
  221. "inoremap <silent> p ;
  222. "inoremap <silent> s r
  223. "inoremap <silent> d s
  224. "inoremap <silent> f t
  225. "inoremap <silent> g d
  226. "inoremap <silent> j n
  227. "inoremap <silent> k e
  228. "inoremap <silent> l i
  229. "inoremap <silent> ; o
  230. "inoremap <silent> n k
  231. "inoremap <silent> E F
  232. "inoremap <silent> R P
  233. "inoremap <silent> T G
  234. "inoremap <silent> Y J
  235. "inoremap <silent> U L
  236. "inoremap <silent> I U
  237. "inoremap <silent> O Y
  238. "inoremap <silent> P :
  239. "inoremap <silent> S R
  240. "inoremap <silent> D S
  241. "inoremap <silent> F T
  242. "inoremap <silent> G D
  243. "inoremap <silent> J N
  244. "inoremap <silent> K E
  245. "inoremap <silent> L I
  246. "inoremap <silent> : O
  247. "inoremap <silent> N K