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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:49:46+00:00 2026-05-28T05:49:46+00:00

I need a macro/function that searches the current document, starting at the top, for

  • 0

I need a macro/function that searches the current document, starting at the top, for a specific pattern. Stopping at the first line that isn’t commented out.

For example in this vim script:

"This is the first line

"This is the third line

if exists("did_something")

It would stop at if line, return true if it found the pattern and false otherwise.

All help appreciated!

  • 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-28T05:49:47+00:00Added an answer on May 28, 2026 at 5:49 am

    Let’s say your pattern is the letter ‘e’.

    To search for a line that is not commented out, but contains an e:

     /^\%(\s*"\)\@!.*e
    

    This uses a negative lookahead (\@!) to confirm that the start of the line (^) isn’t followed by a the beginning of a comment (whitespace and then a double quote \s*") but is followed by an ‘e’ (.*e). The \%( and \) makes the enclosed pattern an atom that other operators (like negative lookahead) can operate on as a unit.

    To run a command on matching lines, use :g

     :g/^\%(\s*"\)\@!.*e/echo "found one"
    

    To see if the current line matches, use match()

     :echo match( getline(line('.')), '^\%(\s*"\)\@!.*e' ) >= 0 ? 'true' : 'false'
    

    The regex is pretty much always the same, the question is what do you want to do with matching lines?

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

Sidebar

Related Questions

I have a function that I need to macro'ize. The function contains temp variables
Let's say that for some reason you need to write a macro: MACRO(X,Y) .
Need a function that takes a character as a parameter and returns true if
I'm trying to make a macro in VBA for Delmia. That macro need to
Just started working on a c project. Need help with passing function pointers/macro functions/etc.
In C++, I need to defined a macro. That macro would take as parameter
I need to pass something like a pointer that takes anything as a function
I am working in a excel macro. In that I need to generate all
Often when describing an issue in code, I need to reference it by line/column/function.
For learning and demonstrating, I need a macro which prints its parameter and evaluates

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.