vimrc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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. "" General Behaviours
  8. """""""""""""""""""""""""""""""""""""""""""""""""""
  9. set autoread "Read a file if it's changed from outside of vim
  10. set splitbelow "New splits appear below current window instead of above
  11. set splitright "New splits appear right of current window
  12. set ttyfast "Smooth movement
  13. " Persistent undo
  14. if has("persistent_undo")
  15. set undofile
  16. set undodir=~/.vimundo
  17. endif
  18. " mouse support. TODO: Are there any checks we should be doing?
  19. set ttymouse=xterm2
  20. set mouse=a
  21. if has("autocmd")
  22. " Enable filetype specific features
  23. filetype plugin indent on
  24. " Clear existing autocmd
  25. autocmd!
  26. " When editing a file, always jump to the last cursor position
  27. autocmd BufReadPost *
  28. \ if line("'\"") > 0 && line ("'\"") <= line("$") |
  29. \ exe "normal! g'\"" |
  30. \ endif
  31. autocmd WinEnter * setlocal cursorline
  32. autocmd WinLeave * setlocal nocursorline
  33. " Source the vimrc file after saving it
  34. autocmd bufwritepost .vimrc source $MYVIMRC
  35. " A way to specify startup actions
  36. autocmd VimEnter * call StartUp()
  37. " if the last window is NERDTree, then close Vim
  38. "autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
  39. else
  40. set autoindent on
  41. endif
  42. """"""""
  43. "" Start Up
  44. """""""""""""""""""""""""""""""""""""""""""""""""""
  45. function! StartUp()
  46. " Stuff in here will be called by autocmd below
  47. " example, start NERDTree if vim called with no arguments
  48. "if 0 == argc()
  49. "NERDTree
  50. "end
  51. endfunction
  52. """"""""
  53. "" Tabs and Text Formatting
  54. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  55. set expandtab " change to single spaces
  56. set tabstop=2 " actual tab press distance
  57. set shiftround " indent to nearest tabstops
  58. set shiftwidth=2 " amount to indent with > and <
  59. set smarttab " backspace tabs where appropriate even if spaces
  60. set softtabstop=2 " let backspace delete indent
  61. set wrap lbr " wrap long lines of text
  62. set backspace=eol,start,indent "backspace over everything
  63. set textwidth=80
  64. """"""""
  65. "" UI - Colours
  66. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  67. syntax enable
  68. colorscheme solarized
  69. set t_Co=16
  70. set background=dark
  71. set colorcolumn=+1
  72. hi Folded ctermfg=darkred "set colour for folded lines
  73. """"""""
  74. "" UI - Numbering
  75. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  76. set number "show line numbers
  77. set ruler "show row,col count in status line
  78. set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
  79. set laststatus=2 "always show a status line
  80. "set relativenumber "current line always 0 (requires 7.3 and up)
  81. """"""""
  82. "" UI - Code Folding
  83. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  84. set foldmethod=indent
  85. set foldlevel=10
  86. set foldtext=MyFoldText()
  87. function! MyFoldText()
  88. let line = getline(v:foldstart)
  89. let indent = indent(v:foldstart)
  90. let indentOnly = strpart(line, 0, indent-1)
  91. let linecount = v:foldend+1 - v:foldstart
  92. let plural = ""
  93. if linecount != 1
  94. let plural = "s"
  95. endif
  96. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  97. return foldtext
  98. endfunction
  99. """"""""
  100. "" UI - Search
  101. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  102. set hlsearch " make searches highlighted
  103. set incsearch " vim will search as you type!
  104. set ignorecase " ignore case for searches
  105. set smartcase " well, unless a user puts in uppercase search characters
  106. set magic " enables wildcard searching
  107. """"""""
  108. "" Key Remaps and Shortcuts
  109. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  110. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  111. " Edit .vimrc
  112. map <leader>v :e $MYVIMRC<CR>
  113. " More convenient escape
  114. imap ii <Esc>
  115. imap II <Esc>
  116. " Add extra lines up and down
  117. nmap <leader>j o<Esc>k
  118. nmap <leader>k O<Esc>j
  119. " Toggle numbering
  120. nmap <silent> <leader>n :set number!<CR>
  121. " Toggle wrap
  122. nmap <silent> <leader>w :set wrap!<CR>
  123. " Toggle paste with/without indenting
  124. nmap <silent> <leader>p :set paste! paste?<CR>
  125. " Toggle showing whitespace characters
  126. nmap <silent> <leader>l :set list! <CR>
  127. " Toggle scrollbind for moving multiple splits in sync together
  128. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  129. " Toggle NERDTree instead of the normal dir browser... Doesn't seem to work yet
  130. map <silent> <leader>d :NERDTreeToggle<CR>
  131. " Toggle Commenting out lines with NERDCommenter
  132. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  133. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  134. " Search with ack!
  135. nnoremap <leader>a :Ack <cword><CR>
  136. nnoremap <leader>A :Ack -a <cword><CR>
  137. vnoremap <leader>a :Ack <cword><CR>
  138. vnoremap <leader>A :Ack -a <cword><CR>
  139. " Colemak layout for INSERT mode only
  140. " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./
  141. " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./
  142. "inoremap <silent> e f
  143. "inoremap <silent> r p
  144. "inoremap <silent> t g
  145. "inoremap <silent> y j
  146. "inoremap <silent> u l
  147. "inoremap <silent> i u
  148. "inoremap <silent> o y
  149. "inoremap <silent> p ;
  150. "inoremap <silent> s r
  151. "inoremap <silent> d s
  152. "inoremap <silent> f t
  153. "inoremap <silent> g d
  154. "inoremap <silent> j n
  155. "inoremap <silent> k e
  156. "inoremap <silent> l i
  157. "inoremap <silent> ; o
  158. "inoremap <silent> n k
  159. "inoremap <silent> E F
  160. "inoremap <silent> R P
  161. "inoremap <silent> T G
  162. "inoremap <silent> Y J
  163. "inoremap <silent> U L
  164. "inoremap <silent> I U
  165. "inoremap <silent> O Y
  166. "inoremap <silent> P :
  167. "inoremap <silent> S R
  168. "inoremap <silent> D S
  169. "inoremap <silent> F T
  170. "inoremap <silent> G D
  171. "inoremap <silent> J N
  172. "inoremap <silent> K E
  173. "inoremap <silent> L I
  174. "inoremap <silent> : O
  175. "inoremap <silent> N K
  176. """"""""
  177. "" Key Remaps - Movement and Windows
  178. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  179. " jump to beginning and end of line easier
  180. nmap H ^
  181. nmap L $
  182. " Smart way to move btw. windows
  183. nmap <C-j> <C-W>j
  184. nmap <C-k> <C-W>k
  185. nmap <C-h> <C-W>h
  186. nmap <C-l> <C-W>l
  187. " window resizing
  188. noremap + <C-w>10+
  189. noremap - <C-w>10-
  190. " mapping to make movements operate on 1 screen line in wrap mode
  191. function! ScreenMovement(movement)
  192. if &wrap
  193. return "g" . a:movement
  194. else
  195. return a:movement
  196. endif
  197. endfunction
  198. onoremap <silent> <expr> j ScreenMovement("j")
  199. onoremap <silent> <expr> k ScreenMovement("k")
  200. onoremap <silent> <expr> 0 ScreenMovement("0")
  201. onoremap <silent> <expr> ^ ScreenMovement("^")
  202. onoremap <silent> <expr> $ ScreenMovement("$")
  203. nnoremap <silent> <expr> j ScreenMovement("j")
  204. nnoremap <silent> <expr> k ScreenMovement("k")
  205. nnoremap <silent> <expr> 0 ScreenMovement("0")
  206. nnoremap <silent> <expr> ^ ScreenMovement("^")
  207. nnoremap <silent> <expr> $ ScreenMovement("$")
  208. """"""""
  209. "" Plugin options
  210. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  211. " let g:NERDTreeQuitOnOpen = 1
  212. " Having problems showing NERDTree arrows in OS X
  213. if has("unix")
  214. let s:uname = system("uname")
  215. if s:uname == "Darwin"
  216. let g:NERDTreeDirArrows=0
  217. endif
  218. endif
  219. " let g:SuperTabDefaultCompletionType = 'context'