!File=[:EVAL:]expand('%')[:END:]
!Author=
!Created=[:EVAL:]strftime('%c')[:END:]
!Last Modified=[:EVAL:]strftime('%c')[:END:]
Program [:EVAL:]expand('%:t:r')[:END:]
Implicit None
<++>
End Program [:EVAL:]expand('%:t:r')[:END:]
And I am calling this as:
"let s:plugin_dir = $HOME.'/.vim/bundle/vimf90/'
let s:plugin_dir=filter(split(&rtp, ','), 'v:val =~ "/vimf90"')[0]
let s:templatedir=s:plugin_dir . '/templates/'
function! Prog(arg)
execute 'r ' . s:templatedir . a:arg . '.txt'
%substitute#\[:EVAL:\]\(.\{-\}\)\[:END:\]#\=eval(submatch(1))#ge
endfunction
So, I am expecting to have the snippet called. But what I am getting is:
!****<= A blank line at top
!File=i.f90
!Author=
!Created=Wed 04 Nov 2015 10:54:29 CET
!Last Modified=Wed 04 Nov 2015 10:54:29 CET
Program i
Implicit None
<++>
0 !****<= Dont know why this "0" is coming
End Program i
So, Though this is called properly, I am getting few crap line. Can you kindly help me cleaning them?
and this is inserting the 0, I dont know why.
If I do,
nnoremap `prg :call Prog("prg")<cr><CR><Esc>gg=G<C-j>
everything is fine.
Kindly help.
By using <C-R>= in insert mode, you are telling Vim, "insert the result of the expression I give you, into the buffer".
Your function has no return value, so I assume the default return value is zero. Thus Vim inserts zero.
Try making your function return an empty string (""), or stick with methods that don't use the expression register (an expression mapping, perhaps, or just move the <Esc> forward to the beginning of the mapping and use the same method as the normal mode mapping).