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:


but it only prints y if I enter this:


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?

1 Answer 1


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

  • 1
    Ooooh that makes sense! Thank you!
    – TornaxO7
    Jan 26, 2021 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.