You are not logged in.

#1 2009-04-11 14:38:47

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

.vimrc and templates.

Just stumbled across templates with gvim/vim I have started playing now I thought it would be nice if I started a file with a filled in top plate.

header.skel

Created By: FMonkey
Created On: DATE
Last modified: Fri Apr 10, 2009  03:51
Decription:

Now this sort of works and the last modified date works on write, with this in vimrc.(Only included for others and clarity)

au BufWritePre * call LastModified()
" If buffer modified, update any 'Last modified: ' in the first 20 lines.
" 'Last modified: Fri 10 Apr 2009 18:04:51 GMT
" Restores position using s mark.
function! LastModified()
  if &modified
    normal ms
    let n = min([20, line("$")])
    exe '1,' . n . 's#^\(.\{,10}Last modified: \).*#\1' .
          \ strftime('%c') . '#e'
    normal `s
  endif
endfun

But as the header.skel where I have DATE I want it to s/DATE/\=strftime("%c")/ now this works fine in command mode, but this line in my vimrc doesn't

au BufNewFile *.py 0read ~/.vim/skeleton/py.skel | 0read ~/.vim/skeleton/header.skel | 1,4 s/^/#/g | 4put='###---###' | 0put='###---###' | s/DATE/\=strftime("%c")/

Now my final end is to try to get to the point when creating a new file it will also put in the shebang and comment out the block depending on file type, now with the .py I have one lined it. Ideally I would like to have the different shebang lines(#!) in one file and use the appropriate one.

So I have 2 real questions one is how do I get DATE to change? I'm guessing my s/ isn't working due to it still being in the buffer.

The other one is how would I approach the filetype shebang lines is it possible to have all the different ones in one file or is this going to involve a complicated function similar to the modified date fun I'm using?

I also have googled till I'm sick but docs regarding templates all seem based around au and I've yet to find a nice simple explanation or example, if someone knows of any docs please point them to me(Mmm and something with a little more clarity than vim help)

I also know there is plenty of template plugins but I'm more interested in learning.

Offline

#2 2009-04-13 10:18:53

FeatherMonkey
Member
Registered: 2007-02-26
Posts: 313

Re: .vimrc and templates.

One little bump then to death it goes.

I just no longer know what to google, and the vim help pages aren't helping.

Offline

Board footer

Powered by FluxBB