Anyway, one thing I'd like to be able to do is insert some
boilerplate text into a document - something like a standard
signature. Is there some way I can preload a buffer with this
text when I run Vim? Can this be done in the rc file? I'm sure
there is a way (with Vim there always seems to be) but I can't
seem to find out how.


In your vimrc, you can add a line something like

        au BufNewFile *.txt $r ~/template.txt

where "*.txt" is the pattern to match.  Thus, if you do:

        :e nonexistant.txt

it will automatically read in the file "~/template.txt" at the bottom of the file ("$").

This can be modified for most templating needs. You can change the filespec to just "*" to have it apply to all new files. You can change the file that is read in. You can also position it elsewhere in the file by changing the "$" to any other address, such as reading at the beginning ("0"). When you're dealing with an empty/new file, this isn't such a big deal though ;)

There are a number of bigger and more powerful templating scripts available, such as

http://vim.sourceforge.net/scripts/script.php?script_id=988
http://vim.sourceforge.net/scripts/script.php?script_id=1160

which may be a bit like hunting mosquitoes with a bazooka, or might be just what you need.

-tim




Reply via email to