Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8779591
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:49:42+00:00 2026-06-13T19:49:42+00:00

How do text editors perform syntax highlighting? I know that vim uses simple regular

  • 0

How do text editors perform syntax highlighting? I know that vim uses simple regular expressions with special extensions to make them more powerful for differentiating syntax elements, but I also know that some other text editors like TextMate allow you to define full parsers. TextMate isn’t known to perform well on large files, but Sublime Text supposedly performs better than vim on large files, and yet supports legacy TextMate syntax parsers. Are there some interesting hacks that it employs to avoid performing a top-to-bottom parse of the file or does it just employ a very efficient parsing algorithm?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:49:43+00:00Added an answer on June 13, 2026 at 7:49 pm

    I wrote a text editor once. I thought I could do better than others. Then I learnt Vim and realized I was wrong 😛 Parts of my highlighting engine still exist on GitHub.

    Several approaches are possible. You could write real lexical analysis (or shallow parsing) routines, but regular expressions may actually be faster if you use them effectively and you’re not an expert in source parsing theory. I used a mix of the two.

    To get good performance, editors are extremely unlikely to be highlighting the entire file. Instead, just highlight the visible region of the file, so you’re minimizing the work done. Of course, then you have to consider what happens as the user starts editing somewhere in the middle of that visible region. My approach was to keep a snapshot of the lexer state (i.e. placement of all tokens and lexical states) in memory all the time, then from the cursor, walk backwards one or two tokens, use the lexer state at that point (i.e. keep the tokens and state stack to the left, and discard the ones to the right) and restart the highlighter from that point until the end of the visible range. Because all (I think) source languages are read from left-to-right, highlighting of tokens further to the left of the edited region should never change.

    EDIT | Just re-reading my source, there were some other optimizations I made along the way. Long lists of keywords (e.g. built-in function names) are expensive to check. I built them into a radix tree which had a huge performance gain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see many text editors for Mac OS X that support Lua syntax highlighting,
Are there any editors that can edit multi-gigabyte text files, perhaps by only loading
I have the standard content editor that uses an iFrame as the text area
I wanna make a text editor but its different other text editors.It will get
Does anyone know of a text editor that searches within search results using regex?
In some of my text editors, there's a feature that draws vertical lines down
By blog-editor i mean text-editors that are used to write blogs online. Example would
I know this is common in 'full featured' IDE's and not text editors but
So, Vim, like most programming-minded text editors, highlights a matching scope character (such as
In normal text editors [with all due respect to Vim] there is a shortcut

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.