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
#!/usr/bin/perl
use strict;
use warnings;
use diagnostics;
EOF

Now, in your vim’s configuration file :

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

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s