Consider using the vim-indent-object plug-in, which allows you to select or delete blocks based on indentation.
As long as your indentation is correct (and that should be easy, since Vim has good Fortran plug-ins to indent your code correctly and the built-in Fortran indentation plugin works well enough), the vim-indent-object motions can accomplish what you describe.
If you're using a plug-in manager such as vim-plug (or Vundle), you can have them install the plug-in directly with something like
After you have it installed, you can use the
aI motions in your Fortran code.
Assuming this block in your code sample:
if (<some condition>) then
text for if block
And your cursor is in the first line of the block (the
if (...) then line), then you can use
dii command ("delete inside indent") to delete the block inside the
if, which in your example means
text for if block. (Of course, this becomes more useful as there are more lines of code and further indentation within that block, which this plug-in should handle nicely.)
Also useful is the
daI command ("delete around indent", note uppercase
I) to delete the indented block, but also the current line and one line below the block with indentation matching the current line. This is useful in Fortran, to include the matching
end if or
end do line. In your example, this would delete the three lines of code, the
if (...) then line, then the indented
text for if block and finally the
end if block.
Of course, you can use these text objects with other operations than "delete", for instance
Vii to visually select the indented block.