From 10df41325f593bf19129e2a61c7348609f58505e Mon Sep 17 00:00:00 2001 From: mo khan Date: Sat, 16 Nov 2019 00:13:46 -0700 Subject: move ruby specific mappings to ruby.vim --- ftplugin/ruby.vim | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 ftplugin/ruby.vim (limited to 'ftplugin/ruby.vim') diff --git a/ftplugin/ruby.vim b/ftplugin/ruby.vim new file mode 100644 index 0000000..78673b7 --- /dev/null +++ b/ftplugin/ruby.vim @@ -0,0 +1,62 @@ +function! AddParameter() + let name = input("parameter name: ") + let cursor_position = getpos(".") + + if empty(matchstr(getline("."), '\')) + exec "?\\" + endif + + let closing_bracket_index = stridx(getline("."), "(") + if closing_bracket_index == -1 + execute "normal A()\" + endif + exec ':s/)/, ' . name . ')/' + exec ':silent! %s/(, /(/' + + call setpos(".", cursor_position) +endfunction + +function! InlineTemp() + let cursor_position = getpos(".") + normal "ayiw + normal $"byiW + normal dd + exec ":.,/end/ s/\\<" . @a . "\\>/" . @b . "/gI" + call setpos(".", cursor_position) +endfunction + +function! 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! 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 AddParameter() +command! RInlineTemp call InlineTemp() +command! RExtractLet call ExtractLet() +command! RRenameVariable call RenameVariable() + +" run rspec test +nnoremap run :!rspec % +nnoremap t :VroomRunNearestTest +nnoremap ta :VroomRunTestFile + +" ruby refactorings +nnoremap rap :RAddParameter +nnoremap rit :RInlineTemp +nnoremap rel :RExtractLet +nnoremap rrlv :RRenameVariable -- cgit v1.2.3