The 'wrap' option is local to the window. (Obviously) Vim does not
switch to the buffer's window when reloading a file -> the option can be
set in the wrong window.
I found that :setf {ft-name} does nothing when auto-reloading a file
(intentionally I guess), so
:au FileType text setl wrap
works better for me. And it somehow looks better anyway ...
Of course you need to define the filetype "text".
In other words ...
Setting a window-local option from a buffer-event like BufRead does not
look right ... and Vim indeed has some separation:
BufRead event -> FileType event
BufRead: buffer must match
FileType: buffer + buffer's window must be current, else FileType event
is not fired
--
Andy
Right: When a buffer is no longer displayed in any window, the old
window-local options are remembered together with other buffer data
and restored when the buffer is displayed again.
But these "hidden" window-local options are not accessible ... they are
only used for restoring.
The gory details are here:
:h local-options
Not sure if this is something for the todo list, i.e.
If a buffer is not shown in any window, window-local options saved together
with the buffer (for restoring) should be accessible with getbufvar().
--
Andy
>> BufRead: buffer must match
>> FileType: buffer + buffer's window must be current, else FileType event
>> is not fired
Ok. It only works this way by accident:
I used :setf text like in the filetype.vim file(s), instead of
:setl ft=text, and :setf is short for
if !did_filetype()
setlocal filetype={filetype}
endif
did_filetype() "returns non-zero when autocommands are being executed
and the FileType event has been triggered at least once." (since
creation of the buffer or so ...).
> Your method does not seem to work for me. My simple test case may be
> too simple. From the vim_use email:
>
>> My actual situation is more complicated. The :setlocal wrap is not in
>> an autocmd, but rather in $HOME/vimfiles/ftplugin/txt.vim, detected by
>> file extension in $HOME/vimfiles/ftdetect/txt.vim with the following
>> command:
>>
>> au BufNewFile,BufRead *.t{e,}xt,*.log,*.csv,*.err set filetype=txt
Use :setf, see above.
> This is the case in which I originally observed the behavior.
>
> When I remove the setlocal wrap from the ftplugin file, and add an
> FileType autocmd to do the same, I get the same results.
no surprise: the trigger is the same.
> It was always my understanding that the ftplugin files only got
> sourced during application of a filetype, which also fires off the
> FileType event. Am I missing something? Or perhaps I'm setting the
> filetype in a strange manner?
--
Andy