Created
September 18, 2010 15:34
-
-
Save h1mesuke/585755 to your computer and use it in GitHub Desktop.
Vim - My vimrc snippet for escaping the selection in various schemes.
This file contains 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
"--------------------------------------- | |
" Escape | |
" html | |
xnoremap <silent> eh :<C-u>call <SID>selection_escape_html()<CR> | |
xnoremap <silent> uh :<C-u>call <SID>selection_unescape_html()<CR> | |
function! s:selection_escape_html() | |
call util#filter_selection("ruby -rcgi -pe '$_ = CGI.escapeHTML($_)'") | |
endfunction | |
function! s:selection_unescape_html() | |
call util#filter_selection("ruby -rcgi -pe '$_ = CGI.unescapeHTML($_)'") | |
endfunction | |
" unicode | |
xnoremap <silent> eU :<C-u>call <SID>selection_escape_unicode()<CR> | |
xnoremap <silent> uU :<C-u>call <SID>selection_unescape_unicode()<CR> | |
function! s:selection_escape_unicode() | |
call util#filter_selection( | |
\ "ruby -pe '$_ = $_.chomp.unpack(\"U*\").map{|i| \"\\\\u%04x\" % i }.join + \"\\n\"'") | |
endfunction | |
function! s:selection_unescape_unicode() | |
call util#filter_selection( | |
\ "ruby -pe 'a=[]; $_.gsub!(/\\u([[:xdigit:]]{4})/) { a[0] = $1.hex; a.pack(\"U\") }'") | |
endfunction | |
" uri | |
xnoremap <silent> eu :<C-u>call <SID>selection_escape_uri()<CR> | |
xnoremap <silent> uu :<C-u>call <SID>selection_unescape_uri()<CR> | |
function! s:selection_escape_uri() | |
call util#filter_selection("ruby -ruri -pe '$_ = URI.escape($_.chomp) + \"\\n\"'") | |
endfunction | |
function! s:selection_unescape_uri() | |
call util#filter_selection("ruby -ruri -pe '$_ = URI.unescape($_)'") | |
endfunction |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment