Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Some of us are familiar with patch failures like "Hunk #11 FAILED at 958." -- is there a command in VIM that allows me to go to, say, 11th hunk ... without having to manually count it? Even a shortcut to go to the next patch would useful.

Is there any?

share|improve this question

2 Answers 2

up vote 1 down vote accepted
+150

A simple method to move between patch hunks is first to search for the beginning of the patch marker

  • in a unified diff

    /^@@Enter

  • in a context diff

    /^\*\{15}Enter

and then to move to the next hunk by repeating the search with

n (or multiple hunks at a time, e.g. 3n)

To move backwards by hunks use

N (or e.g. 4N)


If you know all the hunk numbers you need to see, e.g. the 11th and 24th hunk, you can first use the amount prefix search Hugh suggested: 11/^@@Enter and after that move to 24th hunk either by calculating always from the top: gg24n or by direct forward advance: 13n (hunk #24 is 13 hunks ahead from the 11th).

share|improve this answer
    
Thanks to both Hugh and Jawa for the @@ search trick. And gg24n is something new for me, and that completes the answer to the question. –  Sridhar Ratnakumar Apr 16 '10 at 17:27

Starting from the first line of a patch file in command mode*, you can go to the 11th hunk:-

  • in a context diff:

    11/^\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*Enter

  • in a unified diff:

    11/^@@Enter

* and by command mode, I mean what the help calls normal mode - that is, not insert mode, and not command-line mode (:)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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