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 Plug 'michaeljsmith/vim-indent-object'
.
After you have it installed, you can use the ii
and aI
motions in your Fortran code.
Assuming this block in your code sample:
if (<some condition>) then
text for if block
end if
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.
di
to do? Because either you are talking about the deletion commandd
and a text object likeip
or something like this and then you didn't described the complete text object or you are talking about:di
but I don't see how it's related to fortran. Edit I didn't see Doktor OSwaldo's comment but if you mean "How can I delete a paragraph based on its indentation" it would be worth it to edit your question to make it more clear.sensible
answer? :p