'How to use complex string command in init.vim

I have this string in init.vim:

set background=white " FR!

I want to bind this command to a keymap in init.vim (for find and replace text, that's why I use " FR!, to make sure it will not replace another line):

:!sed -i 's/set background=white " FR!/set background=dark " FR!/g' $MYVIMRC

Of course, the command isn't working, bcause the syntax is wrong. Vim is confusing " as a comment. So what is the correct syntax to execute that command ?

Example use of 'sed':

sed -i 's/old-text/new-text/g' input.txt

_sed is a default tool of linux for find and replace a string in a file, without opening it.

_!sed is tell nvim to execute it as a command, by add '!' before sed.

_$MYVIMRC is a path to init.vim.

_Execute it in : command line is ok, the problem is binding it to a keymap in init.vim.

Summary: Execute the command in nvim, change a setting in init.vim without open init.vim file. So next time I open nvim, it will remember my last change.



Solution 1:[1]

Ok, I need to escape " and ! too.

The correct syntax is insert \ before " and !.

\" \!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ForteD