[英]In Vim, how can I create a dialogue that chooses from possible templates when a new file with certain extension is created?
I'm aware from threads like this one that one can have Vim insert some template code/preamble when a new file is opened, for example 我知道从像线程这一个 ,一个可以使Vim插入一些模板代码/序言一个新的文件被打开时,例如
autocmd BufNewFile *.tex 0r ~/skeleton.tex
but what if I want to choose from multiple templates? 但是,如果我想从多个模板中进行选择怎么办? Is there a way I can use the input()
command to select the filename? 有没有一种方法可以使用input()
命令选择文件名?
I figured this out as I was writing the question, but wanted to make it available to future readers. 在编写问题时,我已经弄清楚了这一点,但希望将其提供给将来的读者。 Just put your templates whichever directory you find suitable, name them appropriately, and place in your .vimrc
只需将您的模板放在您认为合适的任何目录中,并.vimrc
适当命名,然后将其放在.vimrc
autocmd BufNewFile *.<extension> execute "0r <directory>/".input("Template name: ").".<extension>"
...for example, I use tex
for <extension>
, the home directory ~
for <directory>
, and the filenames beamer.tex
, basic.tex
, and article.tex
for different LaTeX options. ...例如,我将tex
用于<extension>
,将主目录~
用于<directory>
,并将文件名beamer.tex
, basic.tex
和article.tex
用于不同的LaTeX选项。 When I start a new file, I type (for example) "basic" when prompted, and it's loaded into the new empty file. 当我启动一个新文件时,在提示时键入(例如)“ basic”,并将其加载到新的空文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.