1

I have this in my init.vim:

autocmd TextChangedI <buffer> echom matchstr(getline(line('.')), "^\s*y")

I was expecting to get the first part of the line if I enter something like that:

        y
 y

but it only prints y if I enter this:

y

according to the docs, \s represents the space and tab character:

|/\s|   \s  \s  whitespace character: <Space> and <Tab>

Now if I use this instead:

autocmd TextChangedI <buffer> echom matchstr(getline(line('.')), "^ *y")

then it works as expected. Why does the first pattern not work? What am I missing?

2

Try :help expr-" and write matchstr(…, '^\s*y') to avoid the back-slash disappearing.

1
  • 1
    Ooooh that makes sense! Thank you!
    – TornaxO7
    Jan 26 at 21:57

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.