Commit 54deff2

mo khan <mo@mokhan.ca>
2014-05-29 21:29:39
add <leader>rel to extract a let.
1 parent 1995e07
Changed files (1)
vimrc
@@ -151,6 +151,18 @@ function! InlineTemp()
   call setpos(".", cursor_position)
 endfunction
 
+function! ExtractLet()
+  let cursor_position = getpos(".")
+  normal 0
+  normal! dd
+  exec "?^\\s*\\<\\(describe\\|context\\)\\>"
+  normal! $p
+  exec 's/\v([a-z_][a-zA-Z0-9_]*) \= (.+)/let(:\1) { \2 }'
+  normal V=
+  call setpos(".", cursor_position)
+  normal jw
+endfunction
+
 " }}}}
 
 "" File type-specific settings {{{{
@@ -329,6 +341,7 @@ nnoremap <leader>T :!ctags -f tags -R<cr>
 " ruby refactorings
 nnoremap <leader>rap :RAddParameter<cr>
 nnoremap <leader>rit :RInlineTemp<cr>
+nnoremap <leader>rel :RExtractLet<cr>
 
 " tagbar
 nnoremap <leader>tb :TagbarToggle<cr>
@@ -346,6 +359,7 @@ command! KillWhitespace :normal :%s/ *$//g<cr><c-o><cr>
 
 command! RAddParameter call AddParameter()
 command! RInlineTemp call InlineTemp()
+command! RExtractLet call ExtractLet()
 
 " }}}