Reputation: 157
I have created this VimScript function to automatically generate a template for newly created latex files (with *.tex
extension)
function CreateLatexTemplate()
normal ggi\documentclass[10pt,a4paper]{article}
normal o\usepackage[latin1]{inputenc}
normal o\usepackage[T1]{fontenc}
normal o\usepackage{amsmath}
normal o\usepackage{amsfonts}
normal o\usepackage{amssymb}
normal o\usepackage{graphicx}
normal o\usepackage[left=1.00cm, right=1.00cm, top=1.00cm, bottom=1.00cm]{geometry}
normal o\author{Author Name}
normal o\begin{document}
normal o\end{document}
normal ko
endfunction
autocmd BufNewFile *.tex call CreateLatexTemplate()
So far it works just fine. But as you can see that I am repeating myself several times in the function CreateLatexTemplate
.
Could someone please suggest a better alternative to my syntax?
Thank you
Upvotes: 1
Views: 430
Reputation: 28349
Apart from using snippet plugin, you can also use a template plugin like vim-template, see also this post.
Upvotes: 1
Reputation: 1574
I don't think there is a better alternative for this syntax, but I want to suggest a different approach.
You may be interested in snippets which are essentially templates that make it easier to enter repeating code patterns. Here is a demo from the Ultisnips repo that shows how it works:
You just need to install the snippets plugin and create a snippet from your template to use it in your work.
This is quite popular approach to writing complex LaTeX documents, you could see this post for more inspiration.
Upvotes: 3