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

  • Home
  • SEARCH
  • 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 586911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:09:22+00:00 2026-05-13T15:09:22+00:00

I have some (log4j generated) logfiles to go through; I know their format pretty

  • 0

I have some (log4j generated) logfiles to go through; I know their format pretty well (I mean I have already got off-the-peg regexes etc I can use).

I want to automatically highlight them in VIM when I load them up (*.log).

A logfile entry looks something like this:

YYYY-MM-DD HH:MM:ss,SSS [...] #LOG-LEVEL# [...] Message

Where #LOG-LEVEL# is one of the standard ‘ERROR’, ‘INFO’, ‘DEBUG’, ‘FATAL’….and the ‘YYYY-MM…’ represents the date/time to millisecond resolution.

To get me started , what are the steps needed to get the date-string highlighted in (say) yellow-background with blue text – and also when the text reads ‘ ERROR ‘ this should have a red-background with white text.

I have tried going through some tutorials on this, but can’t find one which is simple enough to understand, so I’m after some real basic steps here !

Cheers

EDIT:
Here’s the summary of what I did, based on the instructions below:

  1. Created the syntax file ‘log.vim’ in .vim\syntax (see below for example content).

  2. Created a file in .vim\ftdetect\log.vim with the following content:

    au BufRead,BufNewFile *.log set filetype=log

  3. Made sure the following are in my startup settings:

    syntax on
    filetype on

  • 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-05-13T15:09:22+00:00Added an answer on May 13, 2026 at 3:09 pm

    There are three ways of defining syntax items (see :help :syn-define):

    • Keywords: these are for items that are simple strings of keyword characters. This is the fastest matcher.
    • Matches: these are regular expressions for matching.
    • Regions: these are for long regions that are likely to contain other items.

    There are various arguments that make things more complicated (to do with matches within regions etc), see :help :syn-arguments for a discussion of this.

    There is a priority that comes into effect (see :help :syn-priority).

    Colouring is controlled by the highlight command and is separate to the syntax commands.

    A simple way to get started would be to use a match to detect the date and a keyword to detect error. Then use highlight to make the colours come to life:

    " This creates a keyword ERROR and puts it in the highlight group called logError
    :syn keyword logError ERROR
    " This creates a match on the date and puts in the highlight group called logDate.  The
    " nextgroup and skipwhite makes vim look for logTime after the match
    :syn match logDate /^\d\{4}-\d\{2}-\d\{2}/ nextgroup=logTime skipwhite
    
    " This creates a match on the time (but only if it follows the date)
    :syn match logTime /\d\{2}:\d\{2}:\d\{2},\d\{3}/
    
    " Now make them appear:
    " Link just links logError to the colouring for error
    hi link logError Error
    " Def means default colour - colourschemes can override
    hi def logDate guibg=yellow guifg=blue
    hi def logTime guibg=green guifg=white
    

    Bung all of that in ~/.vim/syntax/log.vim and make sure the file type is set properly (see :help filetype.txt) – it should then load automatically.

    Hopefully that should give you something to get going with. Have a (very gradual) read of the various sections of :help syntax.txt and :help usr_44.txt for further info.

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

Sidebar

Related Questions

I have some strings of xxh:yym format where xx is hours and yy is
I have some UI in VB 2005 that looks great in XP Style, but
I have some ASP.NET web services which all share a common helper class they
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
We have some input data that sometimes appears with &nbsp characters on the end.
I have some classes layed out like this class A { public virtual void
I have some C# / asp.net code I inherited which has a textbox which
I have some code like this in a winforms app I was writing to
I have some kind of test data and want to create a unit test
We have some files on our website that users of our software can download.

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.