You are not logged in.

#1 2012-10-31 02:41:48

Jabrick
Member
Registered: 2011-05-13
Posts: 79

[SOLVED] Vim template not loading

Hey guys I'm really unsure why my vim templates won't load.

My templates are stored below in /home/miles/.vim/skel/<mytemplatefile>

[skel]> pwd
/home/miles/.vim/skel
[skel]> ls -l
total 4
-rwxrwxrwx 1 miles users 234 Oct 30 22:17 tmpl.c

And I tried to implementations to get template to load by appending these lines to my ~/.vim/vimrc

"To load template
" The one below is another implmentation that I had tried.
"autocmd BufNewFile *.c 0r ~/.vim/skel/tmpl.c
autocmd! BufNewFile * silent! 0r $HOME/.vim/skel/tmpl.%:e

I have no idea why template won't load for new C files, doesn't seem like anybody else on the internet has this problem.... Thanks.

Last edited by Jabrick (2012-11-04 00:08:04)

Offline

#2 2012-10-31 07:13:00

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED] Vim template not loading

Try this:

autocmd BufNewFile *.c execute ':r ~/.vim/skel/tmpl.c'

Offline

#3 2012-10-31 23:27:57

Jabrick
Member
Registered: 2011-05-13
Posts: 79

Re: [SOLVED] Vim template not loading

Hey thank you for the advice, but it is still not working.
I am beginning to think maybe I am misunderstanding my problem.

What I am expecting to is do something like

vim new_file.c

Where "new_file.c" does not already exist, and it should auto load my template.
This is not currently happening.
Am I misunderstanding my problem or is there something wrong with my vimrc?
I'll post my config on pastebin:  http://pastebin.com/n8ZM3kK9

Offline

#4 2012-11-01 04:06:26

rockin turtle
Member
From: Montana, USA
Registered: 2009-10-22
Posts: 227

Re: [SOLVED] Vim template not loading

I don't know what to tell you.  When I put that line in my .vimrc and added a ~/.vim/skel/tmpl.c file to my system, it would read that file into the current buffer when I did

$ vim new_file.c

if new_file.c didn't exist in $PWD.

I looked at your .vimrc and didn't see anything, but I'm far from a vim expert.  One thing, that line I posted last time resulted in an extra '\n' appended to tmpl.c. The following works for me, though:

autocmd BufNewFile *.c execute ':0r ~/.vim/skel/tmpl.c'

Sorry I don't see what's causing your problem.

Offline

#5 2012-11-04 00:07:25

Jabrick
Member
Registered: 2011-05-13
Posts: 79

Re: [SOLVED] Vim template not loading

@rockin turle
Thank you for your honesty.
I added the line you suggested into my /etc/vimrc (replacing the ~ with appropriate home directory) and it works. I tried afterwards changing the name of my ~/.vim/vimrc file, and it still loads the presets I had there. Not sure exactly whats going on I will have to do some more digging, but for now I have a work around. Thank you for your help.

Offline

Board footer

Powered by FluxBB