Skip to content
This repository was archived by the owner on Jul 12, 2020. It is now read-only.

Commit 02280f7

Browse files
author
Tom Oram
committed
Add local to instance variable to vim bindings
1 parent 52ea30e commit 02280f7

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

docs/vim-bindings.vim

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,14 @@
2525
"
2626
" - RENAME LOCAL VARIABLE
2727
" In normal mode move the cursor so it's inside the name of the variable
28-
" which you want to rename. Press <Leader>rrlv
28+
" which you want to rename. Press <Leader>rlv
2929
"
3030
" You will be prompted for the new name of the variable.
3131
"
32+
" - LOCAL VARIABLE TO INSTANCE VARIABLE
33+
" In normal mode move the cursor so it's inside the name of the variable
34+
" which you want to rename. Press <Leader>rli
35+
"
3236
" - OPTIMIZE USE
3337
" Simple press <Leader>rou to run the optimize use refactoring.
3438

@@ -63,6 +67,24 @@ func! PhpRefactorExtractMethod()
6367
" todo : exit visual mode
6468
endfunc
6569

70+
func! PhpRefactorLocalVariableToInstanceVariable()
71+
" check the file has been saved
72+
if &modified
73+
echom 'Cannot refactor; file contains unsaved changes'
74+
return
75+
endif
76+
77+
let variable=expand('<cword>')
78+
let lineNo=line('.')
79+
80+
exec ':!'.g:php_refactor_command
81+
\ .' convert-local-to-instance-variable'
82+
\ .' %'
83+
\ .' '.lineNo
84+
\ .' '.variable
85+
\ .' | '.g:php_refactor_patch_command
86+
endfunc
87+
6688
func! PhpRefactorRenameLocalVariable()
6789
" check the file has been saved
6890
if &modified
@@ -98,6 +120,6 @@ func! PhpRefactorOptimizeUse()
98120
endfunc
99121

100122
vnoremap <expr> <Leader>rem PhpRefactorExtractMethod()
101-
noremap <expr> <Leader>rrlv PhpRefactorRenameLocalVariable()
123+
noremap <expr> <Leader>rlv PhpRefactorRenameLocalVariable()
124+
noremap <expr> <Leader>rli PhpRefactorLocalVariableToInstanceVariable()
102125
noremap <expr> <Leader>rou PhpRefactorOptimizeUse()
103-

0 commit comments

Comments
 (0)