How to detect vi (not vim) in .vimrc?

扶醉桌前 提交于 2019-12-04 00:29:49

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

Type:

:help if

when in vim for more info.

If you want to get more specific in your checks you can check for individual features too.

I have this in my .vimrc:

if has("eval")
    " Syntax stuff
    let java_highlight_all=1
endif


if has("autocmd")
    " Buffers
    autocmd BufEnter * cd %:p:h
endif

Non-vim doesn't read a .vimrc, it's looking for a .exrc. You can detect older versions of vim using "if version >= 500"

"vi" reads vimrc because it's surely Vim compiled with name "vi". And it's likely compiled "to be very Vi compatible", so you can try to check feature "compatible" to detect "vi":

if !has("compatible")
   let g:loaded_matchparen=1
   syntax off
endif
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!