I'm trying to wrap my head around vim plugin development and I see a constant check on a variable to see if the plugin has already been loaded like:

if exists('g:loaded_plugin') || &cp

This makes sense since it's trying to not load the plugin twice but why is it checking the second part?

I've searched on the documentation on the & and the cp command and it's not ringing anything on my head. As said in the documentation, the & is used to replay the last substitution command and the cp is to get to the next Error.


That checks for the compatible option being set. Usually you don't want plugins to be run when the compatible option is set, because well for one Vim wouldn't actually be compatible anymore and seconds of all, the compatible option e.g. does not allow for line continuations e.g.

let a = 'foobar'
     \ . ' and more text'

You could fix that, by setting a specific cpotions flag, but the general consensus in the Vim community seems to be, to just not bother and skip loading the plugin if Vim starts in compatible mode.

See :help :let-option


To just add a bit more to this, take a look at :help expression-syntax specifically expr9 which shows you can use &option to evaluate the option to its numerical value.

In Vimscript, 0 is false and non-zero is true. With that said, cp is an abbreviation of compatible and that means the if condition is checking the numeric value of the boolean compatible option.

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.