vimrc 7.3 KB

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