The Kate editor has a nice feature: When you're saving a file, it will rerun its filetype detection. Suppose you want to create a new script in ~/bin, so you say
kate ~/bin/myscript
Then type e.g. #!/usr/bin/env perl
and save. In this moment, Kate will recognize that we're talking Perl, and load the syntax highlighting.
In Vim, I thought I could build something similar by means of an autocommand, but I'm stuck with the command that's being executed. I don't see a distinct command for rerunning the filetype detection. It's run by :edit
, so I could say
autocmd BufWritePost * :edit#
But that's rude: It esp. loses the undo history, cursor positions, etc. Is there a better solution?
Well there's a command for that:
:filetype detect
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With