0

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

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?

Community
  • 1
  • 1
Luke Davis
  • 2,548
  • 2
  • 21
  • 43

1 Answers1

1

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

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. When I start a new file, I type (for example) "basic" when prompted, and it's loaded into the new empty file.

Luke Davis
  • 2,548
  • 2
  • 21
  • 43