vimrc 6.6 KB

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