vimrc 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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 ctermfg=darkred "set colour for folded lines
  79. """"""""
  80. "" UI - Numbering
  81. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  82. set number "show line numbers
  83. set ruler "show row,col count in status line
  84. set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
  85. set laststatus=2 "always show a status line
  86. "set relativenumber "current line always 0 (requires 7.3 and up)
  87. """"""""
  88. "" UI - Code Folding
  89. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  90. set foldmethod=indent
  91. set foldlevel=10
  92. set foldtext=FoldText()
  93. """"""""
  94. "" UI - Search
  95. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  96. set hlsearch " make searches highlighted
  97. set incsearch " vim will search as you type!
  98. set ignorecase " ignore case for searches
  99. set smartcase " well, unless a user puts in uppercase search characters
  100. set magic " enables wildcard searching
  101. """"""""
  102. "" Key Remaps and Shortcuts
  103. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  104. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  105. " Edit .vimrc
  106. map <leader>v :e $MYVIMRC<CR>
  107. " More convenient escape
  108. imap ii <Esc>
  109. imap II <Esc>
  110. " Add extra lines up and down
  111. nmap <leader>j o<Esc>k
  112. nmap <leader>k O<Esc>j
  113. nmap <silent> <leader>n :set number!<CR>
  114. nmap <silent> <leader>w :set wrap!<CR>
  115. " Toggle paste mode - no autoindenting of pasted material
  116. nmap <silent> <leader>p :set paste! paste?<CR>
  117. " Toggle visible whitespace characters
  118. nmap <silent> <leader>l :set list!<CR>
  119. " Toggle scrollbind for moving multiple splits in sync together
  120. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  121. " Toggle mouse support.
  122. nnoremap <leader>m :call ToggleMouse()<CR>
  123. " Toggle NERDTree instead of the normal dir browser... Doesn't seem to work yet
  124. nnoremap <silent> <leader>d :NERDTreeToggle<CR>
  125. " Toggle Commenting out lines with NERDCommenter
  126. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  127. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  128. " Traverse undo tree with Gundo!
  129. nnoremap <leader>u :GundoToggle<CR>
  130. " Search under cursor with ack!
  131. nnoremap <leader>a :Ack <cword><CR>
  132. nnoremap <leader>A :Ack -a <cword><CR>
  133. vnoremap <leader>a :Ack <cword><CR>
  134. vnoremap <leader>A :Ack -a <cword><CR>
  135. """"""""
  136. "" Key Remaps - Movement and Windows
  137. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  138. " jump to beginning and end of line easier
  139. nmap H ^
  140. nmap L $
  141. " Smart way to move between windows
  142. nmap <C-j> <C-W>j
  143. nmap <C-k> <C-W>k
  144. nmap <C-h> <C-W>h
  145. nmap <C-l> <C-W>l
  146. " mapping to make movements operate on 1 screen line in wrap mode
  147. onoremap <silent> <expr> j ScreenMovement("j")
  148. onoremap <silent> <expr> k ScreenMovement("k")
  149. onoremap <silent> <expr> 0 ScreenMovement("0")
  150. onoremap <silent> <expr> ^ ScreenMovement("^")
  151. onoremap <silent> <expr> $ ScreenMovement("$")
  152. nnoremap <silent> <expr> j ScreenMovement("j")
  153. nnoremap <silent> <expr> k ScreenMovement("k")
  154. nnoremap <silent> <expr> 0 ScreenMovement("0")
  155. nnoremap <silent> <expr> ^ ScreenMovement("^")
  156. nnoremap <silent> <expr> $ ScreenMovement("$")
  157. """"""""
  158. "" Plugin options
  159. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  160. " let g:NERDTreeQuitOnOpen = 1
  161. " Having problems showing NERDTree arrows in OS X
  162. if s:uname == "Darwin"
  163. let g:NERDTreeDirArrows=0
  164. endif
  165. " let g:SuperTabDefaultCompletionType = 'context'
  166. """"""""
  167. "" Functions, the Givers of Power (in order of use)
  168. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  169. function! FoldText()
  170. let line = getline(v:foldstart)
  171. let indent = indent(v:foldstart)
  172. let indentOnly = strpart(line, 0, indent-1)
  173. let linecount = v:foldend+1 - v:foldstart
  174. let plural = ""
  175. if linecount != 1
  176. let plural = "s"
  177. endif
  178. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  179. return foldtext
  180. endfunction
  181. function! ToggleMouse()
  182. if &mouse == 'a'
  183. set mouse=
  184. echo "Mouse usage disabled"
  185. else
  186. set mouse=a
  187. echo "Mouse usage enabled"
  188. endif
  189. endfunction
  190. function! ScreenMovement(movement)
  191. if &wrap
  192. return "g" . a:movement
  193. else
  194. return a:movement
  195. endif
  196. endfunction
  197. " Colemak layout for INSERT mode only
  198. " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./
  199. " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./
  200. "inoremap <silent> e f
  201. "inoremap <silent> r p
  202. "inoremap <silent> t g
  203. "inoremap <silent> y j
  204. "inoremap <silent> u l
  205. "inoremap <silent> i u
  206. "inoremap <silent> o y
  207. "inoremap <silent> p ;
  208. "inoremap <silent> s r
  209. "inoremap <silent> d s
  210. "inoremap <silent> f t
  211. "inoremap <silent> g d
  212. "inoremap <silent> j n
  213. "inoremap <silent> k e
  214. "inoremap <silent> l i
  215. "inoremap <silent> ; o
  216. "inoremap <silent> n k
  217. "inoremap <silent> E F
  218. "inoremap <silent> R P
  219. "inoremap <silent> T G
  220. "inoremap <silent> Y J
  221. "inoremap <silent> U L
  222. "inoremap <silent> I U
  223. "inoremap <silent> O Y
  224. "inoremap <silent> P :
  225. "inoremap <silent> S R
  226. "inoremap <silent> D S
  227. "inoremap <silent> F T
  228. "inoremap <silent> G D
  229. "inoremap <silent> J N
  230. "inoremap <silent> K E
  231. "inoremap <silent> L I
  232. "inoremap <silent> : O
  233. "inoremap <silent> N K