1

I can't seem to find the answer to this anywhere.

I'm trying to get started with include-search, and since I'm working in golang right now, I'm trying to get vim to include a set of imported files.

E.g.

1    import (
2        "foo"
3        _path "bar"
4        "baz"
5    )

I want everything inside double-quotes, between lines 1 and 5. I got as far as the following but it still only matches one line:

/\v^import \((\n\s+"\zs.*\ze")*

2
  • This is a limitation of vim’s regex :( it’s hard (not impossible) to get multiline matches. I wonder if it’s easier to just match import lines, and use includeexpr to find all the bits between parens?
    – D. Ben Knoble
    Oct 16, 2020 at 13:23
  • It may theoretically be possible with zero-width but 2nd paragraph of :h /\@<= tells us it's not if you have multiple lines you want to "ignore". I got \(^import (\([^"]*"[^"]\+"\)\{-}\)\@<=[^"]*"\zs[^"]\+\ze" match each files of your example if they are joined in one line. But even there, setting include to this pattern only finds the first one. @dbenknoble I don't know if includeexpr can import multiple files as it is also used for gf. Nevertheless, @harv maybe look how/if vim-go does it.
    – perelo
    Oct 18, 2020 at 14:16

0

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.

Browse other questions tagged or ask your own question.