我在同时安装了Vim7.2和Vim7.3的机器之间携带相同的.vimrc。每次我打开一个文件时,安装Vim 7.2的机器都会抱怨我的7.3特定选项:
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忽略这些错误,并且在打开文件时不提示我按enter键?
发布于 2012-06-14 23:10:57
将新选项包含在:
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.
发布于 2012-06-24 12:44:18
可能值得对实际支持的功能进行更细粒度的检查,而不是版本。
例如:
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
发布于 2014-04-11 22:25:31
有时,一个选项是合法的,但在当前环境中不可用。例如:
$ vi
Error detected while processing /home/username/.vimrc:
line 9:
Unknown option: indentexpr=
要测试选项是否存在,并避免出现不可用的错误,请执行以下操作:
if exists("&indentexpr")
:set indentexpr=
endif
https://stackoverflow.com/questions/11035933
复制相似问题