Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore "Unknown option" errors in vimrc

Tags:

vim

I tote the same .vimrc between machines that have both Vim 7.2 and 7.3 installed. The machines with Vim 7.2 complain about my 7.3-specific options every time I open a file:

Error detected while processing /home/spiffytech/.vimrc:
line   72:
E518: Unknown option: rnu
line   73:
E518: Unknown option: undofile
line   74:
E518: Unknown option: undodir=/tmp
line   75:
E518: Unknown option: cryptmethod=blowfish
Press ENTER or type command to continue

How can I make Vim ignore these errors and not prompt me to hit enter whenever I open files?

like image 257
spiffytech Avatar asked Jun 14 '12 15:06

spiffytech


2 Answers

It might be worth doing more fine-grained checking for actual supported features rather than versions.

E.g.:

if has('persistent_undo')
  set undofile
  set undodir=/tmp
endif

" Some options can only be checked with exists('+option'); I'm not sure why
if exists('+relativenumber')
  set rnu
endif

if has('cryptv')
  set cryptmethod=blowfish
end
like image 184
echristopherson Avatar answered Oct 07 '22 11:10

echristopherson


Wrap the new options in:

if version >= 703
  set rnu ...
endif

Check the help for v:version for more info on the version number to use:

                                        *v:version* *version-variable*
v:version       Version number of Vim: Major version number times 100 plus
                minor version number.  Version 5.0 is 500.  Version 5.1 (5.01)
                is 501.  Read-only.  "version" also works, for backwards
                compatibility.
                Use |has()| to check if a certain patch was included, e.g.: >
                        if has("patch123")
<               Note that patch numbers are specific to the version, thus both
                version 5.0 and 5.1 may have a patch 123, but these are
                completely different.
like image 24
sidyll Avatar answered Oct 07 '22 12:10

sidyll