-
Notifications
You must be signed in to change notification settings - Fork 0
/
experimental.vim
88 lines (77 loc) · 3.19 KB
/
experimental.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
nnoremap gf gF
augroup vimrc
autocmd QuickFixCmdPost * botright copen 8
augroup END
function! Async(command, opts)
let opts = copy(a:opts)
let job_options = {'out_io': 'buffer', 'out_modifiable': 0, 'out_msg': 0, 'close_cb': 'CloseHandler'}
let filename = ''
if get(opts, 'filename', '') !=# ''
let filename = get(opts, 'filename', '')
endif
if get(opts, 'out_name', '') !=# ''
let job_options['out_name'] = get(opts, 'out_name', '')
elseif get(opts, 'filename', '') !=# ''
let job_options['out_name'] = 'Job_' . get(opts, 'filename', '')
endif
let logjob = job_start(a:command ." ". filename , job_options)
let buf_num = ch_getbufnr(logjob, "out")
func! CloseHandler(channel) closure
echomsg 'Job "' . a:command . '" done in buffer ' . bufname(buf_num)
endfunc
if get(opts, 'autoswitch', 0) ==# 0
else
execute ':buffer '.buf_num
endif
" if get(opts, 'filetype', '') ==# ''
" else
" execute buf_num . ':bufdo set ft='.get(opts, 'filetype', '')
" endif
endfunction
command! -bang -nargs=* -complete=file RailsTest call Async('bin/rails test', {'filename': <q-args>, 'autoswitch': 1, 'filetype': 'ruby'})
command! -bang -nargs=* -complete=file RailsSpec call Async('rspec ', {'filename': <q-args>, 'autoswitch': 1, 'filetype': 'ruby'})
command! -bang -nargs=* -complete=file ZeusTest call Async('zeus test', {'filename': <q-args>, 'autoswitch': 1, 'filetype': 'ruby'})
command! -bang -nargs=* -complete=file RailsGuard call Async('guard ', {'out_name': 'guard -i ', 'autoswitch': 1, 'filetype': 'ruby'})
command! -bang -nargs=* -complete=file Tail call Async('tail -f', {'filename': <q-args>, 'autoswitch': 1})
command! -bang -nargs=* Flay call Async('flay .', {'autoswitch': 1, 'filetype': 'ruby'})
command! -bang -nargs=* TagsRegenerate call Async('ctags -R --exclude=.git --exclude=log . $(bundle list --paths)', {})
"TODO
"call Async('curl https://httpbin.org/ip', {'autoswitch': 1, 'out_name': 'API'})
function! RunCurrentSpecFile()
let l:filename = expand('%')
call RunSpecs(l:filename)
endfunction
function! RunSpecs(filename)
call Async('zeus test', {'filename': a:filename, 'autoswitch': 0, 'filetype': 'ruby'})
endfunction
command! RunCurrentSpecFile call RunCurrentSpecFile()
" }}}
" nnoremap <leader>1 1gt
" nnoremap <leader>2 2gt
" nnoremap <leader>3 3gt
" nnoremap <leader>4 4gt
" nnoremap <leader>5 5gt
" nnoremap <leader>6 6gt
" nnoremap <leader>7 7gt
" nnoremap <leader>8 8gt
" nnoremap <leader>9 9gt
" nnoremap <leader>0 0gt
"
function! InsertTextBefore(name)
:normal! O
execute "normal! i" . a:name . "\<esc>"
endfunction
command! InsertBreakpoint call InsertTextBefore('binding.pry')
nnoremap <leader>bk :InsertBreakpoint<cr>
augroup VIMRC
autocmd!
autocmd BufLeave *.css normal! mC
autocmd BufLeave *.scss normal! mC
autocmd BufLeave *.html normal! mH
autocmd BufLeave *.erb normal! mH
autocmd BufLeave *.js normal! mJ
autocmd BufLeave *.php normal! mP
autocmd BufLeave *.log normal! mL
autocmd BufLeave *.rb normal! mR
autocmd BufLeave *_spec.rb normal! mT
augroup END