Commit 6e13ee4

mo khan <mo@mokhan.ca>
2014-05-28 22:52:45
add <leader>rap to introduce a parameter to a method.
1 parent 7390d11
Changed files (1)
vimrc
@@ -121,6 +121,24 @@ function! s:setupWrapping()
   set textwidth=72
   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
 " }}}}
 
 "" File type-specific settings {{{{
@@ -296,6 +314,9 @@ nnoremap <leader>gb :Gblame<cr>
 " ctags
 nnoremap <leader>T :!ctags -f tags -R<cr>
 
+" ruby refactorings
+nnoremap <leader>rap :RAddParameter<cr>
+
 " }}}}
 
 "" Command-Line Mappings {{{{
@@ -307,6 +328,8 @@ 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()
+
 " }}}
 
 "" Status Line {{{{
@@ -347,13 +370,6 @@ let g:ctrlp_custom_ignore = {
   \ 'dir':  '\v[\/]\.(git|hg|svn|bzr)$',
   \ 'file': '\v\.(exe|so|dll|swp|wav|mp3|mp4|ogg|pdf|png|jpg|jpeg|bmp|m3u|img|rtf|log|iso|deb|run|part|pls|m4r|ogv|mov|avi|nfo|doc|docx|epub|nfo|m4v|tax|pptx|ini|db|3gp|sfv)$',
   \ }
-"let g:ctrlp_user_command = {
-  "\ 'types': {
-    "\ 1: ['.git', 'cd %s && git ls-files --cached --exclude-standard --others']
-    "\ 2: ['.hg', 'hg --cwd %s locate -I .'],
-    "\ },
-  "\ 'fallback': 'find %s -type f'
-  "\ }
 let g:ctrlp_user_command = 'find %s -type f' 
 let g:ctrlp_working_path_mode = 'ra'
 let g:ctrlp_dotfiles = 0