Skip to content

Instantly share code, notes, and snippets.

@skanev
Created May 4, 2012 07:33
Show Gist options
  • Select an option

  • Save skanev/2592892 to your computer and use it in GitHub Desktop.

Select an option

Save skanev/2592892 to your computer and use it in GitHub Desktop.
Extract a variable in vim script
" 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