Vim script でヒアドキュメント…を書きたかった
Vim script でもヒアドキュメントが書きたいんじゃーって事で少し考えてみた。
Vim script では次のような if 文内のコードは評価がされないのでそれを利用してみた。
if 0 ここは評価されない ああああああああああ いいいいいいいいいいい endif
[ソース]
function! s:here_document(file, line, args) let args = matchlist(a:args, '^\s*\(\S\+\)\s*<<\s*\(\w\+\)\s*$') if empty(args) return "" endif let name = args[1] let identifier = args[2] let text = "" for line in readfile(a:file)[a:line : ] if line =~ '^' . identifier . '$' break endif let text .= line . "\n" endfor return printf("let %s = '%s'", name, text) endfunction command! -nargs=* HereDoc \ execute s:here_document(expand("<sfile>"), expand("<slnum>"), <q-args>) \| if 0 HereDoc g:text << EOS homu mami mado EOS endif echo g:text