6

I have been looking through many resources but cannot seem to find the definition of an atom. In the website link http://vimregex.com/, how does an atom defer from a character in regex?

\{-}
matches 0 or more of the preceding atom, as few as possible

and

\+
matches 1 or more of the preceding characters...
8

A pattern is made up of atoms, from :help /atom:

An atom can be one of a long list of items.  Many atoms match one
character in the text.  It is often an ordinary character or a character
class.  Braces can be used to make a pattern into an atom.
  • An atom can be one of a long list of items, refer to :help /ordinary-atom and :help pattern-atoms to see the long list of items. For example, $ (end-of-line) and ^ (start-of-line) don't match any character but rather they describe a characteristic of the pattern. See :help /zero-width

  • Many atoms match one character in the text. That's why atom and character are used interchangeably, for example a matches a literal a, [0-9a-z] matches one character of the range, \$ and \^ match a literal $ and ^ respectively.

  • Parentheses can be used to make a pattern into an atom, like \(foo\) in:

    \(foo\)\?bar
    

    In this case, the atom \(foo\) matches three characters or atoms: f, o and o .

You could find some examples in this question.

  • Ok, Now I get it. An atom can be one of a long list of items. So, as the OP asked, what is an atom? BTW, in the 3rd bullet I don't see any braces, so it makes even less sense. – Gypsy Spellweaver Aug 7 '17 at 4:37
  • 2
    @GypsySpellweaver the list is everything that's in :h /ordinary-atom, all the way upto 5. Multi items. – muru Aug 7 '17 at 5:03
  • 2
    Now I actually do get it. An atom the smallest thing, along with its modifiers, in the pattern which can match something in the string. The whole pattern is made from a collection of atoms. :h /ordinary-atom helped, The quote from :help /atom merely reinforced the question without answering it. – Gypsy Spellweaver Aug 7 '17 at 5:23

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.