Last active
January 4, 2016 21:09
-
-
Save 29decibel/8678879 to your computer and use it in GitHub Desktop.
vim stringify raw template
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
" 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