I have the following code:

com! -nargs=* ShFoldFunctions <args> fold
ShFoldFunctions syn region shFunctionOne start="^\s*[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\s*()\_s*{"        end="}"
ShFoldFunctions syn region shFunctionTwo start="\%(do\)\@!\&\<[A-Za-z_0-9:,][-a-zA-Z_0-9:]*\>\s*\%(()\)\=\_s*{" end="}"

now I want to do:

let s:funcrgx = "[A-Za-z_0-9:,][-a-zA-Z_0-9:]*"
ShFoldFunctions syn region shFunctionOne start="^\s*".s:funcrgx."\s*()\_s*{" end="}"
ShFoldFunctions syn region shFunctionTwo start="\%(do\)\@!\&\<".s:funcrgx."\>\s*\%(()\)\=\_s*{" end="}"

but it does not work:

"/tmp/1.sh" 12L, 70B
Error detected while processing BufRead Autocommands for "*.sh"..function dist#ft#SetFileTypeSH[45]..dist#ft#SetFileTypeShell[21]..FileType Autocommands for
 "*"..Syntax Autocommands for "*"..function <SNR>9_SynSet[25]..script /usr/share/vim/vim82/syntax/sh.vim:
line  460:
E402: Garbage after pattern: "^\s*".b:funcrgx."\s*()\_s*{"<09><09>end="}"<09>contains=@shFunctionList<09><09> skipwhite skipnl nextgroup=shFunctionStart,shQ
E475: Invalid argument: shFunctionOne<09>matchgroup=shFunction start="^\s*".b:funcrgx."\s*()\_s*{"<09><09>end="}"<09>contains=@shFunctionList<09><09> skipwh
ite skipnl nextgroup=shFunctionStart,shQuickComment
Press ENTER or type command to continue

Can I somehow move the repeated syn start="<regex><regex>" pattern to a variable so that it's not written multiple times?


You can use :execute {expr1} to execute the string that results from the evaluation of {expr1} as an Ex command.

execute "syn sync ...".s:funcrgx."..."

in place of syn sync ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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