I have this code snippet:

# import ipdb; ipdb.set_trace()
def foo():
    import ipdb; ipdb.set_trace()
    # import ipdb; ipdb.set_trace()

How should I specify search query, that it would find only the uncommented ipdb lines?

I guess the command could look something like: /import ipdb/(line start flag)

1 Answer 1


How about this:


The first ^ will anchor the match to the start of the line, [^#] will match any character except a # (the ^ means to match any character except those given), and the * repeats this 0 or more times.

See::help /^ :help /[ for some more information.

Note that this will match all lines with ipdb which don't start with a comment, including:

import other_module, ipdb

If you only want to match those starting with import ipdb, you can use:

/^\s*import ipdb

Here ^ will again anchor the match to the start of the line, \s will match any whitespace character, and * repeats this 0 or more times.

  • @niekas, then add \s* between /^ and [^.
    – romainl
    May 21, 2015 at 8:19
  • So the final query is: /^\s*import ipdb. Thats exactly what I wanted.
    – niekas
    May 21, 2015 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.