11

For C or C++, [{ or ]} can be used in vim to jump to the beginning or end of the code block. Is there a similar shortcut to jump for a code block between a if and endif in vim for Fortran?

The issue is due to not-so-well formatted code, involving a lot of nested if's making the readability difficult. Any solutions for such case?

SKPS
  • 5,433
  • 5
  • 29
  • 63

1 Answers1

11

The built-in but disabled-by-default matchit plugin should help you with that.

Add this line to your vimrc:

runtime macros/matchit.vim

After you restarted Vim you should be able to press % to jump from if to endif and back.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • You may also need to add the line `filetype plugin on` to your `vimrc` before `runtime macros/matchit.vim` – Ross Sep 15 '15 at 15:46
  • Thanks. However, the command confuses with the macros ( `#else` in between). Any solutions for this? – SKPS Sep 16 '15 at 16:17
  • 1
    @Ross : The feature works only macros (#ifdefs). How do extend to normal `if` statements in code? – SKPS Apr 07 '16 at 13:15
  • 1
    @Ross: Could you respond to above comments? – SKPS Aug 03 '16 at 12:25