Thanks for the reply, but I see that I didn't explain the problem
very well. Also, some of my experiments created new buffers instead
of replacing the contents of existing buffers with new filetypes, so
I wasn't replicating the actual problem conditions.
Let me try again.
The actual problem is that I would like to set 'indentexpr' for
buffers with no 'filetype' so that I get indenting behavior that I
think might be useful when just opening Vim and typing notes. To
that end I put the following in my ~/.vimrc.
au BufWinEnter * if &ft == "" || &ft == "text"
\ | setlocal indentexpr=indent(prevnonblank(v:lnum-1))
\ | setlocal indentkeys-=o
\ | let b:undo_ftplugin = "setl inde< indk<"
\ | endif
When I start vim and execute
:echo b:undo_ftplugin
I see
setl inde< indk<
as expected. Further, ":ls" shows
1 %a "[No Name]" line 1
Now, if I open a C file, I expect to have 'indentexpr' empty, either
because the C file is opened in a new buffer or because the C file
was opened in the same buffer and the b:undo_ftplugin was executed.
However, after executing
:e foo.c
:set indentexpr?
I see
indentexpr=indent(prevnonblank(v:lnum-1))
and ":ls" shows
1 %a "foo.c" line 1
I did take your advice about using echom and instrumented
ftplugin.vim differently and verified that when it was executed by
the 'filetype' change to "c", b:undo_ftplugin did not exist.
If ":edit wipes the buffer" as you say, so that b:undo_ftplugin is
deleted, then shouldn't that wiping reset the values of any local
options?
I'm just looking for a way to reset those local options when I edit
a new file, b:undo_ftplugin seemed to be the way to do it, but it
doesn't seem to do anything useful.
Not using :edit is not a solution. For example, if I start vim
and use ":MRU" to open a recently-used C file, I wind up with
'indentexpr' set as above, which wrongly indents C.
Regards,
Gary