Helpfiles and avoiding E21 error with fileencoding
From Vim Tips Wiki
created 2004 · complexity intermediate · author Øystein Urdahl · version 6.0
In 1:6.2-532+1 helpfiles was changed back to not being compressed anymore since that broke :helpg[rep]. That meant that instead of having the suffix .txt.gz they where back to just .txt. Naturally the helpfiles (opened by :help with friends) opens with 'nomodifiable' set since you are supposed to read them and not edit them. For me that made a problem since i had an :au (auto command) in my vimrc setting *.txt to have the iso-8859-1 (latin-1) fileencoding. Now I got an error every time I wanted to use the help system. To overcome this I changed my vimrc from this:
au BufNewFile,BufRead mutt*,*.txt,*/.followup set tw=77 ai nocindent fileencoding=iso-8859-1
" 'nomodifiable' disallows changes to 'fileformat' and 'fileencoding' so remove those entries in the else clause function! Noma_workaround() if exists("modifiable") set tw=77 ai nocindent fileencoding=iso-8859-1 else set tw=77 ai nocindent endif endfunction au BufNewFile,BufRead mutt*,*.txt,*/.followup call Noma_workaround()
In short this just mean that I call the Noma_workaround() function to determine if I can set the fileencoding or if that will give an error. In that case I jsut set the other options.
Your Noma_workaround will almost never set 'filencoding' to latin1 because
tests the existence of a _variable_ with that name. To test the _option_ with that name, you should use
to test if the option is functional, and/or
to test if it is currently true.
See :help exists()