I use my .vimrc on a number of different machines, which all have significantly different versions of vim. Most versions boot up fine, but one of them has reports this (doctored) list of errors on startup:

Error detected while processing ~/.vimrc:
Undefined variable: pathogen
Invalid expression: pathogen#infect()
Invalid :syntax subcommand: enable
Unknown function: executable
Invalid expression: executable('xclip')
:else without :if: else
:endif without :if: endif
Invalid argument: indent on
Invalid argument: plugin on
Invalid argument: nrformats=alpha,hex,octal
Illegal arguments: fromstart
Not an editor command: colorscheme zobean
Unknown option: foldenable
Unknown option: foldcolumn=0
Unknown option: cursorline
Unknown option: winminwidth=0
Ambiguous mapping, conflicts with "^V<silent>"
Ambiguous mapping, conflicts with "^V<leader>"
Ambiguous mapping, conflicts with "j"

I know I can use if has('mouse') to test if mouse support is enabled. Is there a similar test I can do for the other commands, like pathogen, and settings and options that are commonly missing?

Note, I do not have permission to install programs on all of these machines, so installing the latest vim is not a valid option.

I intend to only maintain a single .vimrc for all machines, that will appropriately tailor the options to what is available.

Appendix: vimrc content

I will not include my entire .vimrc, as it about 250 lines long, but below is representative lines and sections causing each of the errors listed above:

execute pathogen#infect()
syntax enable
if has('win32')
elseif executable('xclip')
filetype indent on
filetype plugin on
set nrformats=alpha,hex,octal
syn sync fromstart
colorscheme zobean
set foldenable foldnestmax=5 foldmethod=indent
set foldcolumn=0
set cursorline
set winminwidth=0
vnoremap < <gv
nnoremap <leader>~ vwb<esc>~
vnoremap jk <esc>

1 Answer 1

if exists('*pathogen#infect')
" The function pathogen#infect() exists
" The function pathogen#infect() does not exist

Use :help exists() for more infomation. In addition to variables, exists() is also able to test for &options, *functions, :commands, #event autocommands.

  • It looks like I need exists('*pathogen#infect()') for that test to work correctly, and I will investigate further for its other uses.
    – Zoey Hewll
    May 22, 2018 at 13:31
  • @ZoeyHewll: Great observation, edited.
    – AlexP
    May 22, 2018 at 13:34
  • This works for almost everything I've tried so far, and it unexpectedly solved the 'else without if' errors, but I'm not sure it can solve the strange 'ambiguous mapping' errors, or test for values of options, eg nrformats=alpha,hex,octal
    – Zoey Hewll
    May 24, 2018 at 6:35
  • 1
    @ZoeyHewll: For more complicated cases the usual solution is let v:errmsg=''|silent! <command> and then look at v:errmsg (which should remain empty if all went well).
    – AlexP
    May 24, 2018 at 7:54
  • Update: this seems to not consistently work. Now on my home computer, neither exists('*pathogen#infect') nor exists('*pathogen#infect()') is passing, despite there being a pathogen installation.
    – Zoey Hewll
    May 25, 2018 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.