> 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
You can just set 'autoindent'. This option is ignored in most cases when using 
other ways to define indentation.

> 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
Yes, for some reason empty buffers without edits are used to open a new file. 
You can get the same behavior after “:enew” then “edit bar.c”.

> 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.
Unset 'indentoptions' on any filetype event, adding definition of needed 
autocommand somewhere at the beginning of the vimrc (as it is the first file 
sourced), definitely before “filetype plugin indent on” or similar command, it 
should not interfere with ftplugins then. Use 'autoindent' instead of your 
'indentexpr', it is here just for that reason.

-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Raspunde prin e-mail lui