简体   繁体   English

在Vim中,当创建具有特定扩展名的新文件时,如何创建一个从可能的模板中选择的对话框?

[英]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.texbasic.texarticle.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.

相关问题 使用 bash 脚本从模板创建新文件 - Create new file from templates with bash script 如何在Xcode 4上创建一个新的“模板”类别并在那里使用我自己的文件模板? - How to create a new “templates” category on Xcode 4 and use my own file templates there? 如何在Windows 8模板中为项目添加新类? - How can I add a new class for an Item in Windows 8 Templates? 存储参数模板以从中创建新实体? - Storing parameter templates to create new entities from? 如何在Symfony中使用错误模板创建作曲家捆绑包? - How can I create a composer bundle with error templates in Symfony? 如何将模板从html文件加载到Angular应用中? - How can I load templates from an html file into my Angular app? 可变参数模板 - 如何创建存储传递参数的类型 - Variadic templates - how can I create type, that stores passed arguments 如何在 C# 中创建自定义模板文件夹? - How can I create custom templates folders in C#? 如何为两种或更多数据类型创建 function 模板? - How can I create function templates for the two or more data types? 使用 bash 脚本从模板创建新文件并将文件移动到服务器 - Create new file from templates and moving file to server other with bash script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM