如何在.vimrc 中检测vi(不是vim)? [英] How to detect vi (not vim) in .vimrc?

查看:20
本文介绍了如何在.vimrc 中检测vi(不是vim)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我工作的所有机器上都有一个 vimrc,它自然包含旧 vi 中不存在的选项.

I carry a vimrc to all the machines that I work on and it naturally contains options that are not present in old vi.

如果我不小心在 vi 不是 vim 的别名和/或未安装 vim 的机器上启动 vi 会话,vi 会读取 vimrc 并抛出一堆烦人的错误,让我知道该选项不受支持.

If I accidentally start a vi session on a machine where vi is not an alias to vim and/or vim is not installed, vi reads vimrc and throws a bunch of annoying errors to let me know that option such and such are unsupported.

我知道我总是可以输入vim"而不是vi"并将EDITOR变量设置为vim(对于visudo等...),但是有没有我可以添加到vimrc顶部的行如果文件被 vi 读取,是否提前退出脚本?

I know I can just always type "vim" instead of "vi" and set the EDITOR variable to vim (for visudo etc...), but is there a line I can add to the top of the vimrc that will exit the script early if the file is read by vi?

推荐答案

如果 vi 实际上不是 vim 的链接,则不应读取 .vimrc,而应读取 .exrc.它正在读取 .vimrc 的事实表明它实际上是 vim 的早期版本.如果是这种情况,您可以使用 vim 的if"构造来括起较新的功能,如下所示:

If vi is not actually a link to vim, it should not read .vimrc, it should read .exrc. The fact that it is reading .vimrc indicates it is actually an earlier version of vim. If that is the case, you can use the vim "if" construct to bracket newer features, like this:

:if version >= 500
:  version-5-specific-commands
:endif

类型:

:help if

在 vim 中获取更多信息.

when in vim for more info.

这篇关于如何在.vimrc 中检测vi(不是vim)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆