$ vim --version
VIM - Vi IMproved 8.1
I set up the following vim configuration files:
" .vim/ftplugin/text.vim
set textwidth = 0
" .vim/ftplugin/python.vim
set textwidth = 99
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
Now I do the following:
- Open a text file with vim from the terminal,
vim text.txt
. - Enter insert mode and type a tab.
- Exit to normal mode and open a python file in a split window
:sp python.py
. - Enter insert mode and type a tab.
The result is a long tab in the text file and 4 spaces in the python file, as expected. When I switch between the windows and keep inserting tabs, the text file keeps getting long tabs and the python file keeps getting sets of 4 spaces, as expected.
However, when I do the following:
- Open a python file with vim from the terminal,
vim python.py
. - Enter insert mode and type a tab.
- Exit to normal mode and open a text file in a split window
:sp text.txt
. - Enter insert mode and type a tab.
Both files get a set of 4 spaces. Switching between the windows and inserting more tabs keeps inserting more sets of 4 spaces in both files.
My problem is that vim's behavior is dependent on the order in which I open my files. I realize that I can fix this by explicitly specifying my preferred tab behavior in .vim/ftplugin/text.vim
. However, I'd like to use more file types and vim options than the above, and some vim options are only relevant for specific file types, so I don't want to mirror any vim setting I set for one file type across all the files in ftplugin/
. Is there a way to tell vim that it should revert to it's default behavior for any window's file type (here text) for any options that are not explicitly set in that file type's ftplugin/
(here the tab options)?