diff options
| author | mo khan <mo.khan@gmail.com> | 2019-11-16 11:28:25 -0700 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2019-11-16 11:28:25 -0700 |
| commit | bca21c4ddb43ca0499dd986aea2b2bd4e0959172 (patch) | |
| tree | 0f8b3a8aa251cddaeb4777e116a60c9a20516c5d | |
| parent | 23737bb6496f2c341f203321074ee1942db8db7f (diff) | |
| parent | 10df41325f593bf19129e2a61c7348609f58505e (diff) | |
Merge branch 'master' of github.com:mokhan/vimfiles
| -rw-r--r-- | ftplugin/ruby.vim | 62 | ||||
| -rw-r--r-- | vimrc | 63 |
2 files changed, 62 insertions, 63 deletions
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("."), '\<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! 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 <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> @@ -122,53 +122,6 @@ function! s:setupWrapping() set nolist endfunction -function! 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! 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 - " }}}} "" File type-specific settings {{{{ @@ -242,11 +195,6 @@ cnoremap <expr> <C-P> getcmdline()[getcmdpos()-2] ==# ' ' ? expand('%:p:h') : "\ " Kills Trailing Whitespaces command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr> -command! RAddParameter call AddParameter() -command! RInlineTemp call InlineTemp() -command! RExtractLet call ExtractLet() -command! RRenameVariable call RenameVariable() - " }}} "" General Mappings (Normal, Visual, Operator-pending) {{{{ @@ -319,10 +267,6 @@ nnoremap <leader>p "+p " NERDTree nnoremap <leader>n :NERDTreeFind<cr> nnoremap <localleader>n :NERDTreeClose<cr> -" run rspec test -nnoremap <leader>run :!rspec %<cr> -nnoremap <leader>t :VroomRunNearestTest<cr> -nnoremap <leader>ta :VroomRunTestFile<cr> " open fold nnoremap <space> za " create fold @@ -359,13 +303,6 @@ nnoremap <leader>f :redraw!<cr> nnoremap <leader>gs :Gstatus<cr> nnoremap <leader>gb :Gblame<cr> -" ruby refactorings -nnoremap <leader>rap :RAddParameter<cr> -nnoremap <leader>rit :RInlineTemp<cr> -nnoremap <leader>rel :RExtractLet<cr> -nnoremap <leader>rrlv :RRenameVariable<cr> - - " }}}} "" Status Line {{{{ |
