0

In ex mode,i get the value for set fileencoding.

set fileencoding?
fileencoding=utf-8  

How can assign str with the value utf-8 and print it?

let str=`set fileencoding?`  #it is a wrong statement,i just want to express my meaning
echo str
2
  • 2
    :h :let-option Nov 26 '20 at 9:20
  • 2
    let str = &fileencoding.
    – jdhao
    Nov 26 '20 at 10:04
0

You can use the & prefix to refer to option values as part of Vimscript expressions (or to set them using let statements.)

See :help :let-option for more details.

In your specific case, you can use:

let str = &fileencoding

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.