vim-templates icon indicating copy to clipboard operation
vim-templates copied to clipboard

How to handle the template depending on the filetype?

Open GiancarloAparicio opened this issue 4 years ago • 3 comments

In files like file.blade.php the plugin ignore blade.php.template and takes it as just a php file In files with the filetype modified as (file.tsx -> typescriptreact) the same thing happens too. Trying to fix it I created a little function that reads the current filetype and executes the corresponding template

function! s:CreateNewFile(file)
  call inputsave()
  let l:input = input(a:file, '', 'file')
  silent execute "!ad ".l:input
  silent execute "e ".l:input
  call inputrestore()

  execute 'TemplateInit ' . &filetype
endfunction

El problema es que al crear un archivo directamente desde el shell (archivo vim) obviamente esto no funciona :(

For now I have only limited myself to blocking it with 'g: tmpl_auto initialize' but direct creation is very useful :(

GiancarloAparicio avatar Mar 17 '21 00:03 GiancarloAparicio

Hi Eric,

I am currently very busy and will not be able to work on this plugin in near future. However if you are willing to work on it, I will be happy to guide you.

tibabit avatar Mar 17 '21 04:03 tibabit

#12 same as this issue

tibabit avatar Mar 17 '21 04:03 tibabit

Hi Eric,

I am currently very busy and will not be able to work on this plugin in near future. However if you are willing to work on it, I will be happy to guide you.

Yes, sorry for the delay in responding, I wanted to finish learning a little more about vimscript before trying to give a solution.

I first tried to get the filetype and run TemplateInit, but since bufNewFile triggers filetype it doesn't work, so I tried to catch the filetype just before fetching the template and to my surprise it works.

I really felt silly because there are only 5 new lines and it took me 2 days

image

GiancarloAparicio avatar Mar 25 '21 18:03 GiancarloAparicio