2

I'm trying to configure Vim to be able to properly determine the background color when run inside GNU Screen. I know I need to set the option t_RB to the string \eP\e]11;?\x03\e\\ (where \e is the Escape character) when $TERM starts with screen, but I can't figure out how to use control characters in the set command.

First attempt:

if stridx(environ()['TERM'], 'screen') == 0
    set t_RB=<ESC>P<ESC>]11;?<C-G><ESC>\\
endif

This just set t_RB to the literal string <ESC>P<ESC>]11;?<C-G><ESC>\, which gets output as soon as I start up Vim. I also tried enclosing the string in single quotes, but that didn't help.

Second attempt:

if stridx(environ()['TERM'], 'screen') == 0
    set t_RB="\eP\e]11;?\x07\e\\"
endif

This seemed to just set t_RB to the empty string. I tried again without the quotes and with single quotes; these just resulted in t_RB being set to the string as written, with literal \e instead of an Escape character.

How do I :set an option to a string containing control characters?

1
  • To precisely answer your question would be good to know what is exactly the value you like to get. Commented Nov 24, 2023 at 0:23

1 Answer 1

1

I would do:

if stridx(environ()['TERM'], 'screen') == 0
    let &t_RB="\<ESC>P\<ESC>]11;?\<C-G>\<ESC>\\"
endif
3
  • 1
    I had to strip off two of the backslashes at the end to get what I wanted, but otherwise this worked.
    – jwodder
    Commented Nov 24, 2023 at 0:44
  • Thanks for the feedback. I have adapted the solution. Let me know if the adapted solution is now correct in case other would be interested :-) Commented Nov 24, 2023 at 0:50
  • 1
    Yes, it's now correct.
    – jwodder
    Commented Nov 24, 2023 at 2:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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