Context
I have shortcuts to edit my vimrc
and to source my vimrc
. When I'm writing code I can quickly add a new mapping and then source vimrc
. And all that would be good if I did not use autocmd FileType
for most of my mappings.
Since most mappings are specific to one file type I keep my vimrc
in a form similar to this:
function! FtPython()
setlocal expandtab shiftwidth=4 softtabstop=4 autoindent
nnoremap <buffer> <localleader>c I#<esc>
" Let's say that this is a new mapping
nnoremap <buffer> <localleader>cc ^wC:<esc><left>i
endfunction
if has("autocmd")
augroup filetype_vimrc
autocmd!
autocmd FileType python call FtPython()
...
endif
Yet, when I add a new mapping to FtPython()
and source my vimrc
, the new mapping is not present in the python
buffers because the FileType
event happened long ago, when the file was read.
When I read a buffer back into a window FileType
will be fired and the mapping will be added, but that does not happen when a window is already open and I just move into it (Ctrl+W). In essence, once I add a new mapping all currently open windows need to be "kicked" to get the new mapping.
I work around it by doing (I force the FileType
event to fire):
set ft=python
But that is quite a lot of typing, sometimes I have 2-3 python
files in different windows (split/vsplit
) and I need to do it for each. argdo
is not an option since it will close the windows (as far as I know).
Question
Is there a good way to fire the FileType
event on all windows that Vim is currently showing?
Or, maybe, is there a better way to structure the mappings?
autocmd FileType
has its uses, but local setting are much better left toftplugin
files: then it's Vim's task to apply them at the right moment, not yours. (2) Contrary to the popular belief,vimrc
is not really meant to be sourced multiple times. You can do it, but it takes a lot of careful backwards bending to avoid pitfalls. (3) How aboutbufdo
for updating options.:bufdo
is a good idea. I missed the part about different files.set
commands works with:windo
instead (when you've multiple files in split mode).