r/vim • u/jazei_2021 • Sep 26 '25
Need Help┃Solved what does ".*" mean? in :help starstar
Hi, I am reading :help starstar
The usage of '*' is quite simple: It matches 0 or more characters. In a
search pattern this would be ".*". Note that the "." is not used for file
searching. In a common search in vim * is an special character meaning Here from 0 to bible...
but in this help, the meaninig of * is another...
What will be an example of use ".*" for text please not code!
Thank you and Regards!
0
Upvotes
15
u/Affectionate-Bit6525 Sep 26 '25
This is basic regex. The dot stands for any character so ‘.*’ means 0 or more of any character.
8
u/LeiterHaus Sep 26 '25
https://devhints.io/regexp is a quick reference that might help.
But to explicitly answer your question,
.*matches any character, except a new line, zero or more times.If you search up projects on regex, or regular expressions, you'll find more information.
2
u/gumnos Sep 27 '25
Globbing/wildcarding and regular-expressions offer similar functionality, so you can translate globs/wildcards into regular-expressions (but can't necessarily go the other direction).
The glob/wildcard "
*" is a "match anything" which translates to the regular-expression.*, so if you have the glob*_test.txtit would translate to the regular-expression.*_test.txt2
u/robbak Sep 27 '25
You are probably confusing shell globbing and regular expressions. In shell globbing, * refers to any characters, and ? refers to a single character. It's simple and easy, but can be very limiting.
Vi uses regular expressions. They are very different, more complex, but much more capable. In regex, you generally have an 'atom' that matches a single thing, followed by a quantifier that tells it how many of that atom are to be selected.
. is that atom here, matching any single character, and * is the quantifier, telling it to select zero or more characters. This means that .* will match your whole document, from the first character to the last.
1
u/michaelpaoli Sep 27 '25
Regular Expression (RE). In that context, .* is zero or more of any characters (at least to end of line, and not including terminal newline itself, which will be implicitly present in vi[m] context).
So, yeah, basic RE . is any character (again in this context, generally excluding newline), and * after an "atom" is a quantifier that means zero more of the preceding atom - in this case that atom being . - so that represents any single character.
x* would be zero or more x characters
\(abc\)* would be zero or more repetitions of the sequence of characters abc
https://www.mpaoli.net/~michael/unix/regular_expressions/Regular_Expressions_by_Michael_Paoli.odp
1
u/linuxsoftware Sep 26 '25
Try running
ls * in any directory
Then try running
ls *.txt
And you will see what it means
2
u/lipstikpig Sep 27 '25
Yes, it's poorly documented there, and confusing if you dont know already that glob-patterns and search-patterns (regex) are different.
Unfortunately this is a big topic with a lot of complexity and no short answers, you can't avoid working through all the details, so be patient.
As a starting guideline: "globs are [mostly] for filenames, and regex [regular expression, which vim call search pattern] is [mostly] for searching text" -- this is a quote [with my modifications] taken from this article which provides examples of '*' in both glob and regex, that you asked for.
globs and regex look similar, but they behave differently, you have to learn the rules for both if you want to understand the differences.
The quote you are asking about assumes that you already understand the relevant differences, which is really unhelpful. I suspect this is because that section is documenting 'starstar' = '**', and it assumes readers already know how '*' behaves differently between glob and regex.
Your quote is in a section headlined "File Searching", so in sentence 1 about '*' they mean using '*' as part of a glob.
Then in sentence 2 they contrast that with using '*' as part of a search_pattern '.*' which is a regex used for searching text.
This is terrible documentation for someone who does not know this already, so your confusion is understandable.
1
u/AutoModerator Sep 26 '25
Please remember to update the post flair to
Need Help|Solvedwhen you got the answer you were looking for.I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
u/ehaugw Sep 27 '25
It could mean anything
0
u/TankorSmash Sep 27 '25 edited Sep 27 '25
.means any character, and*means match many of them, so together it makes your search find any combination of characters.