如何忽略vimrc中的“Unknown option”错误?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (2)
  • 关注 (0)
  • 查看 (69)

我在安装Vim 7.2和7.3的电脑之间使用相同的.vimrc。Vim 7.2的电脑每次打开文件时都会报错

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

如何让Vim忽略这些错误?

提问于
用户回答回答于

将新选项包装在:

if version >= 703
  set rnu ...
endif

查看帮助v:version

                                        *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.
用户回答回答于

例如:

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

扫码关注云+社区