1
what does \_. means in vim ?  explain to me character by character

Response from chatgpt:

In Vim regular expressions, \_. is a sequence that represents any character including a newline. 
Here is an explanation of each character:

The backslash \ is an escape character that is used to indicate that the following character has a special meaning in Vim regular expressions. In this case, it is used to escape the underscore character _.
The underscore _ matches any single character, but it does not match newline characters by default.
The dot . matches any character except newline characters.

Therefore, when you combine the \ and _ characters with the dot . character, you get \_., which matches any character, including newline characters
3
  • The underscore _ matches any single character, but it does NOT match newline characters by default. The dot . matches any character EXCEPT newline characters. Therefore, when you combine the \ and _ characters with the dot . character, you get _., which matches any character, INCLUDING newline characters ??? No+No= Yes ?????
    – andrew_ysk
    Commented Apr 7, 2023 at 22:30
  • Just… don't trust ChatGPT, generally. It's good at producing convincing BS (at best).
    – D. Ben Knoble
    Commented Apr 8, 2023 at 15:53
  • LOL. i agree with you this one. I have being using for sometime and realized many time it is a twist and turning tongue.. although sometime it does producing usable data..
    – andrew_ysk
    Commented Apr 9, 2023 at 10:50

1 Answer 1

3

I prefer the explanation of the Vim doc:

\_. Matches any single character or end-of-line.
    Careful: "\_.*" matches all text to the end of the buffer!
\_x Where "x" is any of the characters above: The character class with
    end-of-line added

\_ is an atom modifier that add the new line to some atom matching like . or \s, or\d where:

  • . match any character but new line \_. match any character including new line.
  • \s match any space character but new line \_s match any space including new line.
  • \d match any digit character and not new line \_d match any digit or new line.
2
  • 2
    a ya.. that's more like it.. that's what i found out when tried on vim several times... so the gptchat is totally bs on this stuff. a lot of bs i have encountered on it.
    – andrew_ysk
    Commented Apr 7, 2023 at 22:42
  • ok.. now that you explained like this.. i understood.. thanks a lot. i was like starring on vim help :h _ ...but totally can't understand anything.. However your explanation is wonderful. Thanks
    – andrew_ysk
    Commented Apr 7, 2023 at 22:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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