Jeff MacKinnon's Homepage

Creating vim templates

I always have to re-search how to do this, so this time I think I will just write a quick note for the steps so if I have to do it again from scratch I will know what I have to do.

  1. Create a folder for the templates. I put mine ar ~/.vim/templates/. For this example I will use a template post.rst for a pelican blog post.
  2. Put together the template file. For my example post.rst has the following contents:
Really Cool Title
##################################################
:date: 2024-08-01
:author: jeff
:tags:
:category: ramblings
:slug: slug
:status: hidden
  1. Next modify the ~/.vimrc file. If you don't have one, create it. The code that I need to make this work is:
if has("autocmd")
augroup templates
    autocmd BufNewFile *post.rst 0r ~/.vim/templates/post.rst
augroup END
endif
  1. And done.

I used this post for the bulk of the notes. You should be able to start using these templates immediately. If you want to add more, repeat the steps and add the if to endif portion in the .vimrc and the template file in the templates folder.