Inserting a bunch of lines for any new file in vim

To avoid typing the same lines each time you open up a new file in vim, here is a little trick to do it. Let’s have a try with a simple perl template.

fool@localhost:~$ mkdir .vim

fool@localhost:.vim$cat > perl.template <<EOF
use strict;
use warnings;
use diagnostics;

Now, in your vim’s configuration file :

fool@localhost:~$ cat >> .vimrc <<EOF
au BufNewFile *.pl 0r ~/.vim/perl.template

Anytime you create a new perl script with vim, you will find a few lines already it. Hope it helps !


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.