0

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.

ForteD
  • 41
  • 4
  • Why do you use `sed` and not `:help :s`? And "white" is not a valid value for `set background`. And `init.vim` is for Neovim, not Vim. What are you trying to do, **exactly**? – romainl Feb 19 '22 at 20:53
  • @romainl set background is a feature of Plug 'sainnhe/gruvbox-material'. I bind a keymap for changing it, and then write that setting to init.vim too, so the next time I open vim, it will remember my last change. – ForteD Feb 19 '22 at 21:12

1 Answers1

0

Ok, I need to escape " and ! too.

The correct syntax is insert \ before " and !.

\" \!
ForteD
  • 41
  • 4