I'm currently stuck on this problem.I want, in a vimscript, to replace a variable's brackets when they contain a certain pattern.To say this differently, say I have a variable foo = [content] bar .My purpose is to replace [content] with an empty string, which means that after the substitution we'll get: foo =  bar.The current solution I could find is:let foo = substitute(foo, \[\], ) | let foo = substitute(foo, content, )but couldn't manage to get it in one call.Is there something I'm missing? Could this be done more easily?Regards
Replace brackets and the content within the brackets in a variable
vimscript;substitute;replace
You can do it like this::%s/\[[^]]*\]//gthis somewhat cryptic regexp means to replace everything from start of bracket [ followed by anything not a closing bracket [^]]* followed by the closing bracket ] by nothing.UpdateSince you like to replace variable contents, let me show how to do that.Suppose you have a variable foo (:let foo=[content] bar), then you can do:let foo=substitute(foo, '\[[^]]*\]', '', 'g')The echo '|'.foo.'|' returns | bar| (note the leading space).Make sure, to use single quotation marks, for double quotation marks you need to double the backslashes, as is explained in the help at :h expr-quote