Skip to content

Instantly share code, notes, and snippets.

@sskirby
Created May 7, 2012 20:45
Show Gist options
  • Save sskirby/2630285 to your computer and use it in GitHub Desktop.
Save sskirby/2630285 to your computer and use it in GitHub Desktop.
Useful vim functions
vnoremap <leader>re :call ExtractVariable()<cr>
function! ExtractVariable()
let name = input("Variable name: ")
if name == ''
return
endif
normal! gv
exec "normal c" . name
exec "normal! O" . name . " = "
normal! $p
endfunction
nnoremap <leader>ri :call InlineVariable()<cr>
function! InlineVariable()
normal "ayiw
normal 4diw
normal "bd$
normal dd
normal k$
exec '/\<' . @a . '\>'
exec ':.s/\<' . @a . '\>/' . @b
endfunction
command! ShowRoutes call ShowRoutes()
function! ShowRoutes()
topleft 100 :split __Routes__
set buftype=nofile
normal 1GdG
0r! rake -s routes
exec ":normal " . line("$") . "_ "
normal 1GG
normal dd
endfunction
nnoremap <Leader>% :<C-u>call <SID>copy_path()<CR>
function! s:copy_path()
let @*=expand('%')
let @"=expand('%')
let @+=expand('%')
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment