I carry a vimrc to all the machines that I work on and it naturally contains options that are not present in old vi.
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.
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?
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:
Type:
when in vim for more info.