blob: 5f71c87bb43dd65a65c4d3f09acf3c2bfb2277e9 (
plain)
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
|
function! s:AddParameter()
let name = input("parameter name: ")
let cursor_position = getpos(".")
if empty(matchstr(getline("."), '\<def\>'))
exec "?\\<def\\>"
endif
let closing_bracket_index = stridx(getline("."), "(")
if closing_bracket_index == -1
execute "normal A()\<Esc>"
endif
exec ':s/)/, ' . name . ')/'
exec ':silent! %s/(, /(/'
call setpos(".", cursor_position)
endfunction
function! s:InlineTemp()
let cursor_position = getpos(".")
normal "ayiw
normal $"byiW
normal dd
exec ":.,/end/ s/\\<" . @a . "\\>/" . @b . "/gI"
call setpos(".", cursor_position)
endfunction
function! s:ExtractLet()
let cursor_position = getpos(".")
normal 0
normal! dd
exec "?^\\s*\\<\\(describe\\|context\\|let\\)\\>"
normal! $p
exec 's/\v([a-z_][a-zA-Z0-9_]*) \= (.+)/let(:\1) { \2 }'
normal V=
call setpos(".", cursor_position)
normal jw
endfunction
function! s:RenameVariable()
let cursor_position = getpos(".")
let name = input("new name: ")
normal "ayiw
exec ":.,/end/ s/\\<" . @a . "\\>/" . name . "/gI"
call setpos(".", cursor_position)
endfunction
command! RAddParameter call s:AddParameter()
command! RInlineTemp call s:InlineTemp()
command! RExtractLet call s:ExtractLet()
command! RRenameVariable call s:RenameVariable()
" run rspec test
nnoremap <leader>run :!rspec %<cr>
nnoremap <leader>t :VroomRunNearestTest<cr>
nnoremap <leader>ta :VroomRunTestFile<cr>
" ruby refactorings
nnoremap <leader>rap :RAddParameter<cr>
nnoremap <leader>rit :RInlineTemp<cr>
nnoremap <leader>rel :RExtractLet<cr>
nnoremap <leader>rrlv :RRenameVariable<cr>
" \c comment out line.
nnoremap <buffer> <localleader>c I# <esc>
|