I followed this guide to automatically insert different header templates into new files of different types based on the file extension:
http://www.thegeekstuff.com/2008/12/vi-and-vim-autocommand-3-steps-to-add-custom-header-to-your-file/
It works great! I have a custom header for python source files that is automatically inserted when I open a new .py file.
I want to do a similar thing so that the LaTeX base template is inserted when I open a new .tex file ...
Also, I can't get it to work ...
My ~ / .vimrc says the following:
autocmd bufnewfile *.tex so /home/steve/Work/tex_template.txt
and my tex_template.txt says the following:
:insert \documentclass[a4paper,12pt]{article} .
but when I open a new file as follows:
vim test.tex
(where test.tex no longer exists)
I get this:
"test.tex" [New File] Error detected while processing /home/steve/Work/tex_template.txt: line 2: E492: Not an editor command: :insertdocumentclass[a4paper,12pt]{article} Press ENTER or type command to continue
The problem is with the backslash at the beginning of the line, because if I remove the backslash from tex_template.txt, the new file is opened with documentclass [a4paper, 12pt] {article}. Also, I need a backslash, because otherwise it is not a tex command sequence.
source share