Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I manually rerun vim's filetype detection?

Tags:

vim

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?

like image 466
Stefan Majewsky Avatar asked Mar 30 '12 12:03

Stefan Majewsky


1 Answers

Well there's a command for that:

:filetype detect
like image 198
Zsolt Botykai Avatar answered Nov 11 '22 06:11

Zsolt Botykai