Monday, June 5, 2023

add skeleton to new file based on filetype, not extension

hello,

I'm trying to add skeleton to new files having a filetype (eg python)

here's what  I've tried :

autocmd BufNewFile if &filetype == "python" 0r ~/.vim/python.skel | normal G | let IndentStyle = "python" | endif

with no luck when I open a new file like this :

: bel new | set filetype=python

I know skeleton works , because I have this line that adds it when open a named new file

au BufNewFile *.py 0r ~/.vim/python.skel | normal G | let IndentStyle = "python"


PS: i noticed, when I open a new file with the command above, that adding startinsert at the end causes loading to be much longer and may corrupt dipslay.

this  doesn't work very well:

: bel new | set filetype=python | startinsert

this works well:

: bel new | startinsert | set filetype=python

No comments: