Friday, June 10, 2022

Using autocommand to set local formatprg

i'm running Vim on an Arch Linux build.

When editing *.txt files I want to set the formatprg to use the 'fmt'
program, as well as modifying my 'diffopt' value for those files.

I have the following lines in my .vim/filetype.vim:

~~~~~
if exists("did_load_filetypes")
finish
endif
augroup filetypedetect
" ... stuff for other filetypes
au! BufRead,BufNewFile *.txt setlocal formatprg="fmt -w70 -u"
au! BufRead,BufNewFile *.txt set diffopt-=iwhite diffopt+=iwhiteeol
au! BufEnter *.txt set diffopt-=iwhite diffopt+=iwhiteeol
au! BufLeave *.txt set diffopt-=iwhiteeol diffopt+=iwhite
augroup END
~~~~~

When I edit a *.txt file, I can see that the 'diffopt' is being set
correctly, but the 'formatprg' is not set. I've tried it with 'set' as
well as 'setlocal' and it still doesn't change.

I tried running 'verbose set formatprg' but that tells me nothing.
Doing the same for 'diffopt' tells me it is set in the filetype.vim
file.

Any clues as to why the 'formatprg' option isn't being set? Is it not
allowed to be set by an autocmd? Should I create a text.vim plugin just
to set it?

Thanks in advance for any help.

Spencer

--
--
You received this message from the "vim_use" 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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20220610094249.0d894059%40selket.

No comments: