In org mode there is a way to create a link that will search for text in file./ For example:

[[./functions.pl::sub validate][sub validate]]

This will search for text "sub validate" in file "functions.pl". Unfortunately, there is another function in this file before "validate": sub validate_row.

And the search jumps to it. Can I set the regexp for "sub validate" so it jumped exactly to "validate"?


The docstring for org-link-search says:

Search for a search string S.

If S starts with "#", it triggers a custom ID search.

If S is enclosed within parenthesis, it initiates a coderef search.

If S is surrounded by forward slashes, it is interpreted as a regular expression. [...]

So you can use something like:

[[./functions.pl::/sub validate[^_]/][sub validate]]
  • As soon as I put the bracket [, it stops interpreting it as a link. – user4035 Aug 6 '19 at 14:32
  • 1
    Try editing it by typing C-c C-l with point on it. – JeanPierre Aug 6 '19 at 14:44
  • It worked, but now it gives me a buffer with occurrences of the regexp now. Is it possible to transfer me to the 1-st destination immediately? – user4035 Aug 6 '19 at 15:09
  • Indeed it does jump to found position for simple string search, but present results with occur for a regexp search. Sadly, whitespace is ignored, otherwise we could do a string search on "sub validate " (including a trailing space). – JeanPierre Aug 22 '19 at 9:05
  • If the opening brace { is on the same line, you can use [[./functions.pl::sub validate {][jump]]. – JeanPierre Aug 22 '19 at 9:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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