Created
May 4, 2012 07:33
-
-
Save skanev/2592892 to your computer and use it in GitHub Desktop.
Extract a variable in vim script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " Select an expression, hit <Leader>e and type the variable name | |
| function! ExtractVariable() | |
| try | |
| let save_a = @a | |
| let variable = input('Variable name: ') | |
| normal! gv"ay | |
| execute "normal! gvc" . variable | |
| execute "normal! O" . variable . " = " . @a | |
| finally | |
| let @a = save_a | |
| endtry | |
| endfunction | |
| xnoremap <Leader>e <ESC>:call ExtractVariable()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment