我在创建p.x时使用template-file-loader vim脚本加载模板文件。一个新的乳胶文件。
当我编辑新的tex文件时,template-file-loader脚本能够执行自定义的TemplateFileFunction_tex。
fun! TemplateFileFunc_tex()
let tex_templates = "$HOME/.vim/templates/tex/"
let choice = confirm("Which template should i load",
\ "&presentation\n" .
\ "&hd-presentation\n" .
\ "&paper\n" .
\ "hd-pape&r\n" .
\ "&xelatex-default\n")
if choice == 1 " presentation
execute "0r " . expand(tex_templates . "presentation.tex")
" [...]
endfun
问题是template-file-loader插件使用silent调用该函数。
如何在不更改插件的情况下不使用“unsilent”我的自定义功能?
答案 0 :(得分:3)
我没有看到让confirm
在静默模式下接收用户输入的方法。但您可以使用getchar
代替:
let variants=['&presentation', '&hd-presentation', ...]
echohl MoreMsg
unsilent echo "Which template should I load\n".join(variants, "\n")
echohl None
let reply=getchar()
if type(reply)==type(0)
let reply=nr2char(reply)
endif
if reply is# "\n"
let choice=1
else
let replkeys=map(copy(variants), 'tolower(v:val[stridx(v:val, "&")+1])')
let choice=index(replkeys, reply)+1
endif
if choice==1
...
答案 1 :(得分:0)
这是另一个模板扩展器,但仍然mu-template正确处理最终用户的问题。 e.g。
VimL: " @file {rtp}/templates/tex.template
VimL: " way 1:
VimL: " instructions continued on several lines are not supported
VimL: let s:tex_kind = CONFIRM("Which template should i load", "&presentation\n&hd-presentation\n&paper\nhd-pape&r\n&xelatex-default\n", 1)
VimL: " include {rtp}/templates/tex/internals/presentation.template ?
VimL: if s:tex_kind == 1 | call s:Include('presentation', 'tex/internals') | endif
VimL: " include {rtp}/templates/tex/internals/hd-presentation.template ?
VimL: if s:tex_kind == 2 | call s:Include('hd-presentation', 'tex/internals') | endif
...
VimL: " Way 2
VimL: let s:tex_kind = WHICH("CONFIRM", "Which template should i load", "&presentation\n&hd-presentation\n&paper\nhd-pape&r\n&xelatex-default\n", 1)
VimL: let s:tex_kind = substitute(s:tex_kind, '&', '', 'g')
VimL: call s:Include(s:tex_kind, 'tex/internals')