I use this functions for load configuration for particular extension
function! LoadSnippets(extension)
let file = expand("~/.vim/templates/".a:extension.".snippets.vim")
if filereadable(file)
silent! execute 'source '.file
endif
endfunction
autocmd BufRead,BufNewFile * silent! call LoadSnippets('%:e')
but the if never is True. Without the if, the function work ok.
why the filereadable don’t find the file?
EDIT
I try with
fnamemodify(file,':p')
but is the same.
In the autocommand you are passing the string
'%:e'to your function. Then, in the first line of your function this string is concatenated to form"~/.vim/templates/%:e.snippets.vim".At this point
%and:edo not have any special meaning to Vim. They are not expanded byexpand()and the resulting path will never point to a readable file.Passing
'%:e'directly toexpand()will work though, and this would fix it: