vimrc 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. " so far, this startup just opens NERDTree when there are no arguments
  36. autocmd VimEnter * call StartUp()
  37. else
  38. set autoindent on
  39. endif
  40. """"""""
  41. "" Start Up
  42. """""""""""""""""""""""""""""""""""""""""""""""""""
  43. function! StartUp()
  44. " Stuff in here will be called by autocmd below
  45. if 0 == argc()
  46. "NERDTree
  47. end
  48. endfunction
  49. """"""""
  50. "" Tabs and Text Formatting
  51. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  52. set expandtab " change to single spaces
  53. set tabstop=2 " actual tab press distance
  54. set shiftround " indent to nearest tabstops
  55. set shiftwidth=2 " amount to indent with > and <
  56. set smarttab " backspace tabs where appropriate even if spaces
  57. set softtabstop=2 " let backspace delete indent
  58. set wrap lbr " wrap long lines of text
  59. set backspace=eol,start,indent "backspace over everything
  60. set textwidth=80
  61. """"""""
  62. "" UI - Colours
  63. """"""""""""""""""""""""""""""""""""""""""""""""""""""
  64. syntax enable
  65. colorscheme solarized
  66. set t_Co=16
  67. set background=dark
  68. set colorcolumn=+1
  69. hi Folded ctermfg=darkred "set colour for folded lines
  70. """"""""
  71. "" UI - Numbering
  72. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  73. set number "show line numbers
  74. set ruler "show row,col count in status line
  75. set rulerformat=%55(%{strftime('%a\ %b\ %e\ %I:%M\ %p')}\ %5l,%-6(%c%V%)\ %P%)
  76. set laststatus=2 "always show a status line
  77. "set relativenumber "current line always 0 (requires 7.3 and up)
  78. """"""""
  79. "" UI - Code Folding
  80. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  81. set foldmethod=indent
  82. set foldlevel=10
  83. set foldtext=MyFoldText()
  84. function! MyFoldText()
  85. let line = getline(v:foldstart)
  86. let indent = indent(v:foldstart)
  87. let indentOnly = strpart(line, 0, indent-1)
  88. let linecount = v:foldend+1 - v:foldstart
  89. let plural = ""
  90. if linecount != 1
  91. let plural = "s"
  92. endif
  93. let foldtext = '+'.indentOnly.'... ('.linecount.' More lines)'
  94. return foldtext
  95. endfunction
  96. """"""""
  97. "" UI - Search
  98. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  99. set hlsearch " make searches highlighted
  100. set incsearch " vim will search as you type!
  101. set ignorecase " ignore case for searches
  102. set smartcase " well, unless a user puts in uppercase search characters
  103. set magic " enables wildcard searching
  104. """"""""
  105. "" Key Remaps and Shortcuts
  106. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  107. let mapleader = "," "Leader key lets you make more kinds of shortcuts!
  108. " Edit .vimrc
  109. map <leader>v :e $MYVIMRC<CR>
  110. " More convenient escape
  111. imap ii <Esc>
  112. imap II <Esc>
  113. " Add extra lines up and down
  114. nmap <leader>j o<Esc>k
  115. nmap <leader>k O<Esc>j
  116. " Toggle numbering
  117. nmap <silent> <leader>n :set number!<CR>
  118. " Toggle wrap
  119. nmap <silent> <leader>w :set wrap!<CR>
  120. " Toggle paste with/without indenting
  121. nmap <silent> <leader>p :set paste! paste?<CR>
  122. " Toggle showing whitespace characters
  123. nmap <silent> <leader>l :set list! <CR>
  124. " Toggle scrollbind for moving multiple splits in sync together
  125. nmap <silent> <leader>s :set scrollbind! scrollbind?<CR>
  126. " Toggle NERDTree instead of the normal dir browser... Doesn't seem to work yet
  127. map <silent> <leader>d :NERDTreeToggle<CR>
  128. " Toggle Commenting out lines with NERDCommenter
  129. nnoremap <silent> <leader>, :call NERDComment("n", "toggle")<CR>
  130. vnoremap <silent> <leader>, <ESC>:call NERDComment("x", "toggle")<CR>
  131. " Search with ack!
  132. nnoremap <leader>a :Ack <cword><CR>
  133. nnoremap <leader>A :Ack -a <cword><CR>
  134. vnoremap <leader>a :Ack <cword><CR>
  135. vnoremap <leader>A :Ack -a <cword><CR>
  136. " Colemak layout for INSERT mode only
  137. " Qwerty - qwertyuiopasdfghjkl;'zxcvbnm,./
  138. " Colemak - qwfpgjluy;arstdhneio'zxcvbkm,./
  139. "inoremap <silent> e f
  140. "inoremap <silent> r p
  141. "inoremap <silent> t g
  142. "inoremap <silent> y j
  143. "inoremap <silent> u l
  144. "inoremap <silent> i u
  145. "inoremap <silent> o y
  146. "inoremap <silent> p ;
  147. "inoremap <silent> s r
  148. "inoremap <silent> d s
  149. "inoremap <silent> f t
  150. "inoremap <silent> g d
  151. "inoremap <silent> j n
  152. "inoremap <silent> k e
  153. "inoremap <silent> l i
  154. "inoremap <silent> ; o
  155. "inoremap <silent> n k
  156. "inoremap <silent> E F
  157. "inoremap <silent> R P
  158. "inoremap <silent> T G
  159. "inoremap <silent> Y J
  160. "inoremap <silent> U L
  161. "inoremap <silent> I U
  162. "inoremap <silent> O Y
  163. "inoremap <silent> P :
  164. "inoremap <silent> S R
  165. "inoremap <silent> D S
  166. "inoremap <silent> F T
  167. "inoremap <silent> G D
  168. "inoremap <silent> J N
  169. "inoremap <silent> K E
  170. "inoremap <silent> L I
  171. "inoremap <silent> : O
  172. "inoremap <silent> N K
  173. """"""""
  174. "" Key Remaps - Movement and Windows
  175. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  176. " jump to beginning and end of line easier
  177. nmap H ^
  178. nmap L $
  179. " Smart way to move btw. windows
  180. nmap <C-j> <C-W>j
  181. nmap <C-k> <C-W>k
  182. nmap <C-h> <C-W>h
  183. nmap <C-l> <C-W>l
  184. " window resizing
  185. noremap + <C-w>10+
  186. noremap - <C-w>10-
  187. " mapping to make movements operate on 1 screen line in wrap mode
  188. function! ScreenMovement(movement)
  189. if &wrap
  190. return "g" . a:movement
  191. else
  192. return a:movement
  193. endif
  194. endfunction
  195. onoremap <silent> <expr> j ScreenMovement("j")
  196. onoremap <silent> <expr> k ScreenMovement("k")
  197. onoremap <silent> <expr> 0 ScreenMovement("0")
  198. onoremap <silent> <expr> ^ ScreenMovement("^")
  199. onoremap <silent> <expr> $ ScreenMovement("$")
  200. nnoremap <silent> <expr> j ScreenMovement("j")
  201. nnoremap <silent> <expr> k ScreenMovement("k")
  202. nnoremap <silent> <expr> 0 ScreenMovement("0")
  203. nnoremap <silent> <expr> ^ ScreenMovement("^")
  204. nnoremap <silent> <expr> $ ScreenMovement("$")
  205. """"""""
  206. "" Plugin options
  207. """"""""""""""""""""""""""""""""""""""""""""""""""""""""
  208. " let g:NERDTreeQuitOnOpen = 1
  209. " let g:SuperTabDefaultCompletionType = 'context'