Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • If you change the pattern just to position the cursor at the point you're interested in then you can yank the next word into a register with a separate command:

    function! GotoCFile()
      if search('\v%(^\s*#\s*cfile:\s*)@<=\w')
        normal "zye
        echo 'Found ' . @z
      else
        echo 'Could not find name of corresponding file'
      end
    endfunction

    If however, as suggested by the name of your function, your actual desire is not to put the filename into a variable but to go to that file then it's easier to do that directly:

    function! GotoCFile()
      if search('\v%(^\s*#\s*cfile:\s*)@<=\w')
        find <cfile>
      else
        echo 'Could not find name of corresponding file'
      end
    endfunction

    Use edit instead of find if you don't want to search the path.

    Smylers

    • Thanks! That's useful information. I have to admit, I'm thinking about Emacs just because I find the Vim docs so intensely painful. I'm not Stephen Hawking, but I'm not particularly stupid, either. I don't know why I have such trouble with the Vim docs, but I do. This really should have not been so hard to figure out :/