I write a lf-like file browser demo as below. Now there is a problem: when preview a file in popup, it can be slow if there exists a lot of autocmds, so I abandon autocmd by

vimcmd("noautocmd let winid = '{}'->bufadd()->popup_create({})".format(path, opt))

but then the syntax is gone. And I failed to load correct syntax file after.


Now I can get syntax highligth by manually call set syntax=<filetype>, is there someway to get the filetype by the suffix of the file?

enter image description here

1 Answer 1


To trigger file type detection routine manually (should also set the syntax):

filetype detect
" this is basically a shortcut for
"doautocmd filetypedetect BufRead filename.ext

Note that the target buffer must be set active.

However, the point is that "ftdetect" and "syntax" are the slowest Vim's autocmds by default. So it looks illogical to disable them to speed the things up only to fire manually by the very next line. Perhaps, that's all because you have some very slow plugins/autocmds of your own. Yet in this case it's more useful to revise your configuration and to drop a thing or two, or maybe to forbid to some plugins to mess with "special" buffers and so on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.