Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Given a code like this:

588          while ($linecounter > 0) {
589             $token = " ";
590             while ($token != PHP_EOL) {
591                 if (fseek($handle, $pos, SEEK_END) == -1) {
592                     $beginning = true;
593                     break;
594                 }
595                 $token = fgetc($handle);
596                 $pos--;
597             }
598             $linecounter--;
599             if ($beginning) {
600                 rewind($handle);
601             }
602         }

The cursor is at the character = in the line 590.

Which is the most efficient way to select the code block:

  1. lines 590-597
  2. lines 591-596 (just the inner part)
share|improve this question

migrated from serverfault.com Aug 6 '11 at 12:42

This question came from our site for professional system and network administrators.

2 Answers 2

up vote 12 down vote accepted

To do the first:

  • Hit $ to go to the end of the lineover the {
  • Push v or V (depending on whether you want to select lines or not)
  • Push % (to jump to the matching bracket).

To select just the inner part, go inside the inner part and use the i{ directional modifier.

For example, to delete everything inside the current {…} block, type: di{.

share|improve this answer
    
Wow, I have just learned how to use yi(, thanks :) –  takeshin Aug 11 '11 at 9:05
  1. $ to jump to the end of the line you're on (to be over the opening brace)
    v to begin a selection (V for whole lines)
    % to jump to the matching brace.

  2. j to go down one line so your cursor is inside the braces you are trying to select
    v to begin a selection (V for whole lines)
    i{ select everything inside the braces

share|improve this answer
    
+1 for nice formatting –  takeshin Aug 11 '11 at 9:06
    
Method 2 is probably the best method here, since the $ movement in method 1 only works because the opening brace is at the end of the line. Method 2 works without the j movement if your cursor is anywhere within the braces. –  SpoonMeiser Oct 11 '11 at 11:23

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.