7

I have a regular expression, ^ \{3,}/, and want to use the value of a setting or variable in place of the 3. Here's the context:

match LeadingSpaces /^ \{3,}/
highlight LeadingSpaces ctermbg=red guibg=red

I'd like to use the value of tabstop in place of 3. Alternatively, I could set a new variable to be used.

xn.
  • 15,776
  • 2
  • 30
  • 34

1 Answers1

8

Try the following instead of match LeadingSpaces /^ \{3,}/:

execute 'match LeadingSpaces /^ \{'.&tabstop.',}/'
Andrew Clark
  • 202,379
  • 35
  • 273
  • 306
  • Thanks. This works. Is there a way to compile a string into a regex pattern so the setting expansion could be applied only to `'/^ \{'.&tabstop.',}/'`? – xn. May 15 '12 at 19:12
  • You could save the string `'/^ \{'.&tabstop.',}/'` to a variable and then do something like `execute 'match LeadingSpaces '.regex`. – Andrew Clark May 15 '12 at 19:46