Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including
Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Vi and Vim Stack Exchange is a question and answer site for people using the vi and Vim families of text editors. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
6 years, 1 month ago
I have notorious problems finding the right autocommand events for various settings. Usually, my choices seem to be okay, but then there are situations where the settings are reset to default values. In particular, I would like to know the events to use for the following activities:
formatoptions to a value of my choice such that any file-type-specific settings are overwritten
choosing a specific file type for files with a particular file name extension
setting the syntax highlighting synchronization mode
Feb 4, 2017 at 0:23
Wolfgang Jeltsch Wolfgang Jeltsch
345 1 1 gold badge 2 2 silver badges 11 11 bronze badges
The solution for the first issue depends on whether you want to set particular
formatoptions values for each filetype, or set certain
formatoptions values for all filetypes.
If the former, simply put your
formatoptions settings in a file named
~/.vim/after/ftplugin/<filetype>.vim on Unix, or
~\vimfiles\after\ftplugin\<filetype>.vim on Windows.
If the latter, simply put a
FileType autocommand in your
~/.vimrc file, e.g.,
au FileType * setlocal formatoptions-=o
There are a number of ways to do this. The simplest is to put a command like this
au BufRead,BufNewFile *.<extension> set filetype=<filetype>
in a file named
~/.vim/ftdetect/<filetype>.vim (on Unix).
There are a number of ways to do this as well. I usually put the syntax sync command, e.g.,
syntax sync fromstart
in a file named
~/.vim/after/syntax/<filetype>.vim (on Unix).
You can find more examples with
Feb 4, 2017 at 5:02
6,144 18 18 silver badges 20 20 bronze badges
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our
Accept all cookies
Necessary cookies only