简体   繁体   中英

Vim filetype settings not loading when creating a file

I have defined several .vim files in the ftplugin directory for some of the languages I work with. When opening files that already exist, the settings in these files load correctly. However, when I am creating a new file (ie by running vim filename.py ) the corresponding settings are not loaded until after I save the file (so that it exists on disk), close vim, and re-open it.

Is there a way to get vim to load filetype setting from ftplugin for files that vim is creating?

A filetype like Python is determined based on its file extension (cp. $VIMRUNTIME/filetype.vim ):

au BufNewFile,BufRead *.py,*.pyw        setf python

With BufNewFile , the filetype is applied to newly created files, too. This only doesn't work for filetypes that are detected by inspecting the buffer contents (eg a shebang like #!/bin/bash in the first line), not based on a file pattern. For these, it is indeed necessary to save (and re-edit) the file, or to :setf manually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM