Wikia

Vim Tips Wiki

Changes: Helpfiles and avoiding E21 error with fileencoding

Edit

Back to page

(dodgy tip, not very helpful in general cases)
(adjust previous/next navigation + minor manual clean)
 
Line 2: Line 2:
 
{{TipImported
 
{{TipImported
 
|id=727
 
|id=727
|previous=726
+
|previous=725
 
|next=732
 
|next=732
|created=May 18, 2004
+
|created=2004
 
|complexity=intermediate
 
|complexity=intermediate
 
|author=Øystein Urdahl
 
|author=Øystein Urdahl
|version=5.7
+
|version=6.0
 
|rating=5/2
 
|rating=5/2
 
|category1=
 
|category1=

Latest revision as of 10:19, April 23, 2011

Tip 727 Printable Monobook Previous Next

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

to this:

" '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.

CommentsEdit

Your Noma_workaround will almost never set 'filencoding' to latin1 because

if exists("modifiable")

tests the existence of a _variable_ with that name. To test the _option_ with that name, you should use

if exists("+modifiable")

to test if the option is functional, and/or

if &modifiable

to test if it is currently true.

See :help exists()


Around Wikia's network

Random Wiki