Skip to content

Instantly share code, notes, and snippets.

@29decibel
Last active January 4, 2016 21:09
Show Gist options
  • Save 29decibel/8678879 to your computer and use it in GitHub Desktop.
Save 29decibel/8678879 to your computer and use it in GitHub Desktop.
vim stringify raw template
" little vim function
" make raw contents string
" turn following raw template
" <div class="show">
" <span>{{data.name}}</span>
" </div>
" into string:
" '<div class="show">' +
" '<span>{{data.name}}</span>' +
" '</div>'
function! Stringify() range
for linenum in range(a:firstline, a:lastline)
let replaceSub = "'\\1'\ +"
if a:lastline == linenum
let replaceSub = "'\\1'"
endif
let newline = getline(linenum)
" escape single quote
let newline = substitute(newline,"\'", '"' ,'g')
" add single quotes and plus
let newline = substitute(newline,'\(\S.*\)', replaceSub ,'g')
call setline(linenum, newline)
endfor
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment