12

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

15

How about this:

/^[^#]*ipdb

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.

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

Your Answer

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

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