3

Please explain following two lines found in synload.vim file:

let s:cpo_save = &cpo
set cpo&vim

What is vim in the last expression? What is result of such an expression, and what does it affect?

  • 1
    What is vim in the last expression? See :h set-&vim – Matt Mar 25 at 4:46
  • 2
    Does this answer your question? Is cpo&vim a special syntax? – Martin Tournoij Mar 25 at 22:34
  • 1
    While, I totally agree with you all, the help page doesn't explain why the plugins have this habit. – Luc Hermitte Mar 26 at 12:25
  • 1
    l00p, I've edited your question to make it less of a dupe (and more relevant to @LucHermitte 's answer). If you feel the edits go against the grain of the question you were asking, feel free to revert them. But I feel the question stands better on it's own this way – D. Ben Knoble Mar 26 at 14:42
  • 1
    Fair enough @LucHermitte; I've retracted the duplicate vote. – Martin Tournoij Mar 27 at 2:57
6

It resets 'cpo' value to its default value.

Some people may be running vim in compatible mode, by choice or not. In those cases, various things would be inhibited, things we usually rely upon when writing plugins -- in particular :h line-continuation. As a consequence, the plugins would emit many error messages.

Resetting 'cpo' to its factory setting, the plugin becomes resilient to these hostile (IMO) configurations.

This syntax could be used with many (all?) vim options. Before doing that, we record the old value in order to properly restore it afterward

let s:cpo_save = &cpo
set cpo&vim
.
. plugin code
.
let &cpo = s:cpo_save
| improve this answer | |
  • @BLayer Indeed. thanks :) – Luc Hermitte Mar 25 at 1:16
  • 1
    No problemo :) ... – B Layer Mar 25 at 3:01

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.