Guest User

Untitled

a guest
Jan 31st, 2013
552
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. " Stefan Schmidt's .vimrc
  2. " http://github.com/schlubbi
  3. "
  4. " thanks to Gary Bernhardt https://github.com/garybernhardt
  5.  
  6.  
  7. set t_Co=256
  8. set nocompatible                  " Must come first because it changes other options.
  9.  
  10. silent! call pathogen#runtime_append_all_bundles()
  11.  
  12. syntax on                     " Turn on syntax highlighting.
  13. filetype plugin indent on         " Turn on file type detection.
  14.  
  15. runtime macros/matchit.vim        " Load the matchit plugin.
  16.  
  17. set showcmd                       " Display incomplete commands.
  18. set showmode                      " Display the mode you're in.
  19.  
  20. set backspace=indent,eol,start    " Intuitive backspacing.
  21.  
  22. set hidden                        " Handle multiple buffers better.
  23.  
  24. set wildmenu                      " Enhanced command line completion.
  25. set wildmode=longest,list         " complete files like a shell.
  26.  
  27. set ignorecase                    " Case-insensitive searching.
  28. set smartcase                     " But case-sensitive if expression contains a capital letter.
  29.  
  30. set number                        " Show line numbers.
  31. set ruler                         " Show cursor position.
  32.  
  33. set incsearch                     " Highlight matches as you type.
  34. set hlsearch                      " Highlight matches.
  35.  
  36. set wrap                          " Turn on line wrapping.
  37. set scrolloff=3                   " Show 3 lines of context around the cursor.
  38.  
  39. set title                         " Set the terminal's title
  40.  
  41. set visualbell                    " No beeping.
  42. set cursorline
  43. set nobackup                      " Don't make a backup before overwriting a file.
  44. set nowritebackup                 " And again.
  45. set cmdheight=2
  46. set tabstop=2                    " Global tab width.
  47. set shiftwidth=2                 " And again, related.
  48. set expandtab                    " Use spaces instead of tabs
  49. set numberwidth=5
  50. set showtabline=2
  51. set winwidth=79
  52.  
  53. " Store temporary files in a central spot
  54. set backup
  55. set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
  56. set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp
  57.  
  58. " This makes RVM work inside Vim. I have no idea why.
  59. set shell=/bin/sh
  60. set laststatus=2                  " Show the status line all the time
  61.  
  62. " Useful status information at bottom of screen
  63. set statusline=[%n]\ %<%.99f\ %h%w%m%r%y\ %{fugitive#statusline()}%{exists('*CapsLockStatusline')?CapsLockStatusline():''}%=%-16(\ %l,%c-%v\ %)%P
  64.  
  65. " Prevent Vim from clobbering the scrollback buffer. See
  66. " http://www.shallowsky.com/linux/noaltscreen.html
  67. set t_ti= t_te=
  68. " keep more context when scrolling off the end of a buffer
  69. set scrolloff=3
  70.  
  71. "Color Settings
  72. "colorscheme railscasts
  73. " set t_Co=256
  74. " set background=dark
  75. " color solarized
  76. " color codeschool
  77.  
  78. " solarized options
  79. let g:solarized_termcolors = 256
  80. let g:solarized_visibility = "high"
  81. let g:solarized_contrast = "high"
  82. colorscheme solarized
  83. " Map leader key to ','
  84. let mapleader=","
  85.  
  86. set guifont=Monaco:h12
  87. let g:NERDTreeWinPos = "right"
  88. set guioptions-=T " Removes top toolbar
  89. set guioptions-=r " Removes right hand scroll bar
  90. set go-=L " Removes left hand scroll bar
  91.  
  92. " keep longer history
  93. set history=1000
  94.  
  95. " Make the current window big, but leave others context
  96. set winwidth=84
  97. " We have to have a winheight bigger than we want to set winminheight. But if
  98. " we set winheight to be huge before winminheight, the winminheight set will
  99. " fail.
  100. set winheight=5
  101. set winminheight=5
  102. set winheight=999
  103.  
  104. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  105. " KEY MAPPINGS
  106. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  107. " Insert a hash rocket with <c-l>
  108. imap <c-l> <space>=><space>
  109.  
  110. " Clear the search buffer when hitting return
  111. function! MapCR()
  112.   nnoremap <cr> :nohlsearch<cr>
  113. endfunction
  114. call MapCR()
  115. nnoremap <leader><leader> <c-^>
  116.  
  117. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  118. " MULTIPURPOSE TAB KEY
  119. " " Indent if we're at the beginning of a line. Else, do completion.
  120. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  121. "function! InsertTabWrapper()
  122. "  let col = col('.') - 1
  123. "  if !col || getline('.')[col - 1] !~ '\k'
  124. "    return "\<tab>"
  125. "  else
  126. "    return "\<c-p>"
  127. "  endif
  128. "endfunction
  129. "inoremap <tab> <c-r>=InsertTabWrapper()<cr>
  130. "inoremap <s-tab> <c-n>
  131.  
  132. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  133. " ARROW KEYS ARE UNACCEPTABLE
  134. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  135. map <Left> <Nop>
  136. map <Right> <Nop>
  137. map <Up> <Nop>
  138. map <Down> <Nop>
  139.  
  140. " Edit or view files in same directory as current file
  141. cnoremap %% <C-R>=expand('%:h').'/'<cr>
  142. map <leader>e :edit %%
  143. map <leader>v :view %%
  144.  
  145.  
  146. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  147. " RENAME CURRENT FILE
  148. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  149. function! RenameFile()
  150.     let old_name = expand('%')
  151.     let new_name = input('New file name: ', expand('%'), 'file')
  152.     if new_name != '' && new_name != old_name
  153.       exec ':saveas ' . new_name
  154.       exec ':silent !rm ' . old_name
  155.       redraw!
  156.     endif
  157. endfunction
  158. map <leader>n :call RenameFile()<cr>
  159.  
  160. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  161. " PROMOTE VARIABLE TO RSPEC LET
  162. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  163. function! PromoteToLet()
  164.  :normal! dd
  165.  " :exec '?^\s*it\>'
  166.  :normal! P
  167.  :.s/\(\w\+\) = \(.*\)$/let(:\1) { \2 }/
  168.  :normal ==
  169. endfunction
  170. :command! PromoteToLet :call PromoteToLet()
  171. :map <leader>p :PromoteToLet<cr>
  172.  
  173. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  174. " COMMAND-T CONFIG
  175. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  176. map <leader>gr :topleft :split config/routes.rb<cr>
  177. function! ShowRoutes()
  178.  " Requires 'scratch' plugin
  179.  :topleft 100 :split __Routes__
  180.  " Make sure Vim doesn't write __Routes__ as a file
  181.   :set buftype=nofile
  182.   " Delete everything
  183.   :normal 1GdG
  184.   " Put routes output in buffer
  185.   :0r! bundle exec rake -s routes
  186.   " Size window to number of lines (1 plus rake output length)
  187.   :exec ":normal " . line("$") . _ "
  188.   " Move cursor to bottom
  189.   :normal 1GG
  190.   " Delete empty trailing line
  191.   :normal dd
  192. endfunction
  193. map <leader>gR :call ShowRoutes()<cr>
  194.  
  195. let g:CommandTCancelMap=['<ESC>','<C-c>']
  196. " Open files with <leader>f
  197. map <leader>f :CommandTFlush<cr>\|:CommandT<cr>
  198.  
  199. " Open files, limited to the directory of the current file, with <leader>gf
  200. " This requires the %% mapping found below.
  201. map <leader>F :CommandTFlush<cr>\|:CommandT %%<cr>
  202.  
  203. " Custom Rails-specific Command-T mappings
  204. map <leader>gv :CommandTFlush<cr>\|:CommandT app/views<cr>
  205. map <leader>gc :CommandTFlush<cr>\|:CommandT app/controllers<cr>
  206. map <leader>gm :CommandTFlush<cr>\|:CommandT app/models<cr>
  207. map <leader>gh :CommandTFlush<cr>\|:CommandT app/helpers<cr>
  208. map <leader>gl :CommandTFlush<cr>\|:CommandT lib<cr>
  209. map <leader>gp :CommandTFlush<cr>\|:CommandT public<cr>
  210. map <leader>gs :CommandTFlush<cr>\|:CommandT public/stylesheets<cr>
  211.  
  212. " Other Rails-specific file keystrokes
  213. map <leader>gg :topleft 100 :split Gemfile<cr>
  214.  
  215. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  216. " CUSTOM AUTOCMDS
  217. " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  218. augroup vimrcEx
  219. " Clear all autocmds in the group
  220.   autocmd!
  221.   autocmd FileType text setlocal textwidth=78
  222.   " Jump to last cursor position unless it's invalid or in an event handler
  223.   autocmd BufReadPost *
  224.     \ if line("'\"") > 0 && line("'\"") <= line("$") |
  225.     \   exe "normal g`\"" |
  226.     \ endif
  227.  
  228.   " for ruby, autoindent with two spaces, always expand tabs
  229.   autocmd FileType ruby,haml,eruby,yaml,html,javascript,sass,cucumber set ai sw=2 sts=2 et
  230.   autocmd FileType python set sw=4 sts=4 et
  231.   autocmd! BufRead,BufNewFile *.sass setfiletype sass
  232.   " Indent p tags
  233.   autocmd FileType html,eruby if g:html_indent_tags !~ '\\|p\>' | let g:html_indent_tags .= '\|p\|li\|dt\|dd' | endif
  234.  
  235.   " Leave the return key alone when in command line windows, since it's used
  236.   " to run commands there.
  237.   autocmd! CmdwinEnter * :unmap <cr>
  238.   autocmd! CmdwinLeave * :call MapCR()
  239. augroup END
  240.  
  241. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  242. " SWITCH BETWEEN TEST AND PRODUCTION CODE
  243. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  244. function! OpenTestAlternate()
  245.   let new_file = AlternateForCurrentFile()
  246.   exec ':e ' . new_file
  247. endfunction
  248. function! AlternateForCurrentFile()
  249.   let current_file = expand("%")
  250.   let new_file = current_file
  251.   let in_spec = match(current_file, '^spec/') != -1
  252.   let going_to_spec = !in_spec
  253.   let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<helpers\>') != -1
  254.   if going_to_spec
  255.     if in_app
  256.        let new_file = substitute(new_file, '^app/', '', '')
  257.     end
  258.     let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
  259.     let new_file = 'spec/' . new_file
  260.   else
  261.     let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
  262.     let new_file = substitute(new_file, '^spec/', '', '')
  263.     if in_app
  264.       let new_file = 'app/' . new_file
  265.     end
  266. endif
  267. return new_file
  268. endfunction
  269. nnoremap <leader>. :call OpenTestAlternate()<cr>
  270. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  271. " RUNNING TESTS
  272. """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  273. map <leader>t :call RunTestFile()<cr>
  274. map <leader>T :call RunNearestTest()<cr>
  275. map <leader>a :call RunTests('')<cr>
  276. map <leader>c :w\|:!script/features<cr>
  277. map <leader>w :w\|:!script/features --profile wip<cr>
  278.  
  279. function! RunTestFile(...)
  280.   if a:0
  281.     let command_suffix = a:1
  282.   else
  283.     let command_suffix = ""
  284.   endif
  285.  
  286.   " Run the tests for the previously-marked file.
  287.   let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\)$') != -1
  288.     if in_test_file
  289.       call SetTestFile()
  290.     elseif !exists("t:grb_test_file")
  291.       return
  292.     end
  293.     call RunTests(t:grb_test_file . command_suffix)
  294. endfunction
  295.  
  296. function! RunNearestTest()
  297.   let spec_line_number = line('.')
  298.   call RunTestFile(":" . spec_line_number . " -b")
  299. endfunction
  300.  
  301. function! SetTestFile()
  302. " Set the spec file that tests will be run for.
  303.   let t:grb_test_file=@%
  304. endfunction
  305.  
  306. function! RunTests(filename)
  307.  " Write the file and run tests for the given filename
  308.  :w
  309.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  310.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  311.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  312.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  313.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  314.  :silent !echo;echo;echo;echo;echo;echo;echo;echo;echo;echo
  315.  if match(a:filename, '\.feature$') != -1
  316.    exec ":!script/features " . a:filename
  317.  else
  318.    if filereadable("script/test")
  319.      exec ":!script/test " . a:filename
  320.    elseif filereadable("Gemfile")
  321.      exec ":!bundle exec rspec --color " . a:filename
  322.    else
  323.      exec ":!rspec --color " . a:filename
  324.    end
  325.  end
  326. endfunction
RAW Paste Data