If you want manual control over when and where to insert the
boilerplate, you can define a function and optionally connect it to a
keystroke sequence:
" Insert boilerplate text at current cursor
function! AddBoilerPlate()
r ~/boilerplate.txt
endfunction
command! -nargs=0 BoilerPlate :call AddBoilerPlate()
map <F8> <ESC>:BoilerPlate<CR>
This will put the boilerplate text where the cursor is. There may be
(probably are--I'm fairly green at scripting) better ways to do this,
but it's one way.
Just stick that somewhere neatly in your vimrc and bang away.
Daryl
-----Original Message-----
From: Tim Chase [mailto:[EMAIL PROTECTED]
Sent: Thursday, November 02, 2006 1:34 PM
To: Richard Querin
Cc: [email protected]
Subject: Re: How do I implement boilerplate text?
> 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