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 314827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:14:08+00:00 2026-05-12T08:14:08+00:00

How would you go about marking all of the lines in a buffer that

  • 0

How would you go about marking all of the lines in a buffer that are exact duplicates of other lines? By marking them, I mean highlighting them or adding a character or something. I want to retain the order of the lines in the buffer.

Before:

foo
bar
foo
baz

After:

foo*
bar
foo*
baz
  • 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-12T08:14:08+00:00Added an answer on May 12, 2026 at 8:14 am

    As an ex one-liner:

    :syn clear Repeat | g/^\(.*\)\n\ze\%(.*\n\)*\1$/exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' | nohlsearch
    

    This uses the Repeat group to highlight the repeated lines.

    Breaking it down:

    • syn clear Repeat :: remove any previously found repeats
    • g/^\(.*\)\n\ze\%(.*\n\)*\1$/ :: for any line that is repeated later in the file
      • the regex
        • ^\(.*\)\n :: a full line
        • \ze :: end of match – verify the rest of the pattern, but don’t consume the matched text (positive lookahead)
        • \%(.*\n\)* :: any number of full lines
        • \1$ :: a full line repeat of the matched full line
      • exe 'syn match Repeat "^' . escape(getline('.'), '".\^$*[]') . '$"' :: add full lines that match this to the Repeat syntax group
        • exe :: execute the given string as an ex command
        • getline('.') :: the contents of the current line matched by g//
        • escape(..., '".\^$*[]') :: escape the given characters with backslashes to make a legit regex
        • syn match Repeat "^...$" :: add the given string to the Repeat syntax group
    • nohlsearch :: remove highlighting from the search done for g//

    Justin’s non-regex method is probably faster:

    function! HighlightRepeats() range
      let lineCounts = {}
      let lineNum = a:firstline
      while lineNum <= a:lastline
        let lineText = getline(lineNum)
        if lineText != ""
          let lineCounts[lineText] = (has_key(lineCounts, lineText) ? lineCounts[lineText] : 0) + 1
        endif
        let lineNum = lineNum + 1
      endwhile
      exe 'syn clear Repeat'
      for lineText in keys(lineCounts)
        if lineCounts[lineText] >= 2
          exe 'syn match Repeat "^' . escape(lineText, '".\^$*[]') . '$"'
        endif
      endfor
    endfunction
    
    command! -range=% HighlightRepeats <line1>,<line2>call HighlightRepeats()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to know how I would go about altering the HTML that
First of all, I know there are a few other StackOverflow questions about this
I have 15 BackgroundWorers that are running all the time, each one of them
I'm wondering how i would go about making the following application: a user signs
How would i go about making an animation of a rocket move to another
How would I go about making a reference to a UILabel inside a variable?
Any ideas how I would go about writing a javascript method to insert an
Just a quick question about how you would go about implementing this. I want
Anyone have any idea how I would go about converting a timestamp in milliseconds
Does anyone know how I would go about changing (transforming) an image based on

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.