18

In scripts it is customary to do something like:

let s:save_cpo = &cpo
set cpo&vim

... script ...

let &cpo = s:save_cpo

To ensure nocompatible mode for the script.

Is:

set cpo&vim

some sort of special syntax, as in foo & bar? Or is it more like a command, trigger line or something else?

Runium
  • 1,237
  • 10
  • 20

2 Answers2

17

Yes, it's a special syntax to reset options to the Vim defaults. From :help :set-&vim:

:se[t] {option}&        Reset option to its default value.  May depend on the
                        current value of 'compatible'. {not in Vi}
:se[t] {option}&vi      Reset option to its Vi default value. {not in Vi}
:se[t] {option}&vim     Reset option to its Vim default value. {not in Vi}

:se[t] all&             Set all options, except terminal options, to their
                        default value.  The values of 'term', 'lines' and
                        'columns' are not changed. {not in Vi}

I found it by just typing :help &vim (which also goes to :help :set-&vim) :-)

Martin Tournoij
  • 62,054
  • 25
  • 192
  • 271
  • 5
    Thanks, my bad. I've been looking at cpo, http://vimdoc.sourceforge.net/htmldoc/usr_41.html#use-cpo-save etc. – Runium Feb 23 '15 at 00:44
6

cpo means compatible option and & means option variable, so &cpo represents the value of compatible option.

set cpo&vim is a special syntax which tells vim to reset the option of cpo which defaults to aABceFs.

See the doc in :h cpo

statox
  • 49,782
  • 19
  • 148
  • 225
hw3a
  • 61
  • 1
  • 1