Goal: write code to do block commenting/uncommenting while keeping the current indentation level. This has been solved, see here for my code
Current problem: use s/// to match a line that begins with spaces/tabs and then a comment character, which will depend on the file being modified. In this case, I want to move from
// this is a comment that can be toggled on/off
to
this is a comment that can be toggled on/off
With my cursor on the commented line above:
:let b:commentChar='//'
:s@(^\s*)\=b:commentChar\s*@\1@
I have tried escaping the parentheses, escaping or unescaping the =, and using \v which someone told me would be "magic".
This does not work. (I didn't want to use / or # as the delimiter because my variable can be // or # and didn't want to use : as I need that for scoping with b:commentChar).
:h :execute,:h escape(), &:h 'commentstring'– Peter Rincker Apr 17 '18 at 20:59