vimrc 8.1 KB

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