├── after └── plugin │ └── hashrocket.vim └── plugin └── hashrocket.vim /after/plugin/hashrocket.vim: -------------------------------------------------------------------------------- 1 | " vim:set ft=vim et tw=78 sw=2: 2 | 3 | if exists('g:afterloaded_hashrocket') 4 | finish 5 | endif 6 | let g:afterloaded_hashrocket = 1 7 | 8 | if ! exists(":Q") 9 | command! Q :quit 10 | endif 11 | -------------------------------------------------------------------------------- /plugin/hashrocket.vim: -------------------------------------------------------------------------------- 1 | " hashrocket.vim 2 | " vim:set ft=vim et tw=78 sw=2: 3 | 4 | if exists('g:loaded_hashrocket') 5 | finish 6 | endif 7 | let g:loaded_hashrocket = 1 8 | 9 | if $HASHROCKET_DIR == '' && expand('') =~# '/dotmatrix/\.vim/plugin/hashrocket\.vim$' 10 | let $HASHROCKET_DIR = expand('')[0 : -38] 11 | endif 12 | if $HASHROCKET_DIR == '' && filereadable(expand('~/.bashrc')) 13 | let $HASHROCKET_DIR = expand(matchstr("\n".join(readfile(expand('~/.bashrc')),"\n")."\n",'\n\%(export\)\=\s*HASHROCKET_DIR="\=\zs.\{-\}\ze"\=\n')) 14 | endif 15 | if $HASHROCKET_DIR == '' 16 | let $HASHROCKET_DIR = substitute(system("bash -i -c 'echo \"$HASHROCKET_DIR\"'"),'\n$','','') 17 | endif 18 | if $HASHROCKET_DIR == '' 19 | let $HASHROCKET_DIR = expand('~/hashrocket') 20 | endif 21 | 22 | function! s:HComplete(A,L,P) 23 | let match = split(glob($HASHROCKET_DIR.'/'.a:A.'*'),"\n") 24 | return map(match,'v:val[strlen($HASHROCKET_DIR)+1 : -1]') 25 | endfunction 26 | command! -bar -nargs=1 Hcommand :command! -bar -bang -nargs=1 -complete=customlist,s:HComplete H :bang> $HASHROCKET_DIR/args> 27 | 28 | Hcommand cd 29 | Hcommand lcd 30 | Hcommand read 31 | Hcommand edit 32 | Hcommand split 33 | Hcommand saveas 34 | Hcommand tabedit 35 | 36 | command! -bar -range=% NotRocket :,s/:\(\w\+\)\s*=>/\1:/ge 37 | 38 | function! HTry(function, ...) 39 | if exists('*'.a:function) 40 | return call(a:function, a:000) 41 | else 42 | return '' 43 | endif 44 | endfunction 45 | 46 | if &grepprg ==# 'grep -n $* /dev/null' 47 | set grepprg=grep\ -rnH\ --exclude='.*.swp'\ --exclude='*~'\ --exclude='*.log'\ --exclude=tags\ $*\ /dev/null 48 | endif 49 | set list " show trailing whiteshace and tabs 50 | if &statusline == '' 51 | set statusline=[%n]\ %<%.99f\ %h%w%m%r%{HTry('CapsLockStatusline')}%y%{HTry('rails#statusline')}%{HTry('fugitive#statusline')}%#ErrorMsg#%{HTry('SyntasticStatuslineFlag')}%*%=%-14.(%l,%c%V%)\ %P 52 | endif 53 | 54 | if has('persistent_undo') 55 | set undofile 56 | set undodir^=~/.vim/tmp//,~/Library/Vim/undo 57 | endif 58 | 59 | let g:rubycomplete_buffer_loading = 1 60 | let g:rubycomplete_rails = 1 61 | 62 | if !exists('g:rails_projections') 63 | let g:rails_projections = {} 64 | endif 65 | 66 | call extend(g:rails_projections, { 67 | \ "app/presenters/*.rb": { 68 | \ "command": "presenter", 69 | \ "test": "spec/presenter/{}_spec.rb", 70 | \ "alternate": "spec/presenter/{}_spec.rb", 71 | \ "template": "class {camelcase|capitalize|colons}\nend" } 72 | \ }, 'keep') 73 | 74 | if !exists('g:rails_gem_projections') 75 | let g:rails_gem_projections = {} 76 | endif 77 | 78 | call extend(g:rails_gem_projections, { 79 | \ "active_model_serializers": { 80 | \ "app/serializers/*_serializer.rb": { 81 | \ "command": "serializer", 82 | \ "template": "class {camelcase|capitalize|colons}Serializer < ActiveModel::Serializer\nend", 83 | \ "affinity": "model"}}, 84 | \ "rspec-core": { 85 | \ "spec/support/*.rb": { 86 | \ "command": "support"}}, 87 | \ "cucumber": { 88 | \ "features/*.feature": { 89 | \ "command": "feature", 90 | \ "template": "Feature: {capitalize|blank}"}, 91 | \ "features/support/*.rb": { 92 | \ "command": "support"}, 93 | \ "features/support/env.rb": { 94 | \ "command": "support"}, 95 | \ "features/step_definitions/*_steps.rb": { 96 | \ "command": "steps"}}, 97 | \ "carrierwave": { 98 | \ "app/uploaders/*_uploader.rb": { 99 | \ "command": "uploader", 100 | \ "template": "class {camelcase|capitalize|colons}Uploader < CarrierWave::Uploader::Base\nend"}}, 101 | \ "draper": { 102 | \ "app/decorators/*_decorator.rb": { 103 | \ "command": "decorator", 104 | \ "affinity": "model", 105 | \ "template": "class {camelcase|capitalize|colons}Decorator < ApplicationDecorator\nend"}}, 106 | \ "fabrication": { 107 | \ "spec/fabricators/*_fabricator.rb": { 108 | \ "command": ["fabricator", "factory"], 109 | \ "alternate": "app/models/{}.rb", 110 | \ "related": "db/schema.rb#{pluralize}", 111 | \ "test": "spec/models/{}_spec.rb", 112 | \ "template": "Fabricator :{} do\nend", 113 | \ "affinity": "model"}}, 114 | \ "factory_girl": { 115 | \ "spec/factories/*.rb": { 116 | \ "command": "factory", 117 | \ "alternate": "app/models/{}.rb", 118 | \ "related": "db/schema.rb#{pluralize}", 119 | \ "test": "spec/models/{}_spec.rb", 120 | \ "template": "FactoryGirl.define do\n factory :{} do\n end\nend", 121 | \ "affinity": "model"}, 122 | \ "spec/factories.rb": { 123 | \ "command": "factory"}, 124 | \ "test/factories.rb": { 125 | \ "command": "factory"}} 126 | \ }, 'keep') 127 | 128 | " Generic non-Rails projections with projectile.vim 129 | if !exists('g:projectionist_heuristics') 130 | let g:projectionist_heuristics = {} 131 | endif 132 | 133 | call extend(g:projectionist_heuristics, { 134 | \ "config.rb&source/": { 135 | \ "source/stylesheets/*.sass": { "command" : "stylesheet" }, 136 | \ "source/stylesheets/*.scss": { "command" : "stylesheet" }, 137 | \ "source/stylesheets/*.css": { "command" : "stylesheet" }, 138 | \ "source/javascripts/*.js": { "command" : "javascript" }, 139 | \ "source/javascripts/*.coffee": { "command" : "javascript" }, 140 | \ "source/*.html": { "command" : "view" }, 141 | \ "source/*.haml": { "command" : "view" }, 142 | \ "config.rb": { "command" : "config" } 143 | \ } 144 | \ }, 'keep') 145 | 146 | inoremap `^ 147 | 148 | " copy to end of line 149 | nnoremap Y y$ 150 | " copy to system clipboard 151 | vnoremap gy "+y 152 | " copy whole file to system clipboard 153 | nnoremap gY gg"+yG 154 | 155 | 156 | " Enable TAB indent and SHIFT-TAB unindent 157 | vnoremap >gv 158 | vnoremap g y :Ggrep " 166 | 167 | function! s:align() 168 | let p = '^\s*|\s.*\s|\s*$' 169 | if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p) 170 | let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g')) 171 | let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*')) 172 | Tabularize/\\\@[6 q" 181 | let &t_EI .= "\[2 q" 182 | endif 183 | 184 | if executable('ag') 185 | let g:ackprg = 'ag --vimgrep' 186 | endif 187 | 188 | function! s:unused_steps(bang) abort 189 | let savegp = &grepprg 190 | 191 | let prg = "hr unused" 192 | if a:bang | let prg = prg.' -f' | endif 193 | let &grepprg = prg 194 | 195 | try 196 | silent grep! 197 | finally 198 | let &grepprg = savegp 199 | endtry 200 | 201 | copen 202 | redraw! 203 | endfunction 204 | 205 | command! -bang UnusedSteps call unused_steps("") 206 | 207 | augroup hashrocket 208 | autocmd! 209 | 210 | autocmd CursorHold,BufWritePost,BufReadPost,BufLeave * 211 | \ if isdirectory(expand(":h")) | let &swapfile = &modified | endif 212 | 213 | autocmd BufRead * if ! did_filetype() && getline(1)." ".getline(2). 214 | \ " ".getline(3) =~? '<\%(!DOCTYPE \)\=html\>' | setf html | endif 215 | 216 | autocmd FileType gitcommit setlocal spell 217 | autocmd FileType ruby setlocal comments=:#\ tw=79 218 | 219 | autocmd Syntax css syn sync minlines=50 220 | 221 | autocmd FileType help nnoremap q :q 222 | autocmd FileType ruby nmap bt BlockToggle 223 | autocmd FileType cucumber 224 | \ inoremap :call align()a 225 | autocmd BufRead *_spec.rb map l ExtractRspecLet 226 | autocmd FileType sql nmap t :w \| call Send_to_Tmux("\\i ".expand("%")."\n") 227 | augroup END 228 | --------------------------------------------------------------------------------