Reputation: 8434
It seems like there's some odd caching-like behavior going on for files that I have already opened once in Vim. I have a file foo.txt
that I opened, and then I change some of the settings in ~/.vim/after/ftplugin/text.vim
, but those new settings do not appear in foo.txt
. I can quit vim and reopen foo.txt
, or reload with :e
, or even :so ~/.vim/after/ftplugin/text.vim
, but none of these seem to have an effect on foo.txt
's settings. If I mv foo.txt bar.txt
, the settings show up for bar.txt
with no issues.
EDIT
It seems I can force the settings to reload for foo.txt
with the following sequence:
:so ~/.vimrc
:so ~/.vim/after/ftplugin/text.vim
Questions:
~/.vimrc
not enough? It applied settings that were directly specified in ~/.vimrc
, but shouldn't the ftplugins have been loaded at the line filetype plugin indent on
? Why was sourcing text.vim
afterwards necessary?Upvotes: 1
Views: 811
Reputation: 32946
A few more precisions:
.vimrc
is loaded once -> for defining global stuff.gvimrc
, loaded only with gvim after the .vimrc
macros/
scripts (loaded explicitly/manually)As you see, all things are loaded once, only. If you want to load them several times, you'll have to do it manually and explicitly. That's why a few of us have a :Reload
command that simplifies reloading any kind of script - mine is hidden in my collection of scripts: lh-misc -> plugin/vim-maintain.vim
Upvotes: 1
Reputation: 3086
Vim runtime consists of a few hundred files, I'm not sure why you expect Vim to monitor them continuously. It doesn't. These files are loaded at some well-defined (and documented) points, that's all there is to it.
In particular there is no safe way to reload your configuration. You can do things like :so ~/.vimrc
, but unless you specifically wrote your vimrc
to take that into account, there will be drawbacks (such as autocmd
s piling up). If you want to be safe you have to quit Vim and start it again. That's how Vim works.
Now, for ftplugin
s you might get away with something like this:
:setf text
(use the actual filetype instead of text
). This works for simple set fubar
options. It works because under the hood setf
is actually a carefully written autocmd
. It still breaks for more complicated constructs (such as autocmd
s or file-scoped variables), for the same reasons :so ~/.vimrc
has drawbacks.
Upvotes: 2