1

I have tried without any luck, but can anyone kindly let me know if di is possible for language like vim/fortran which has structure like

   do loop
      Something
   end do

UPDATE: command di', di", di{, di[, di( delete content inside the given surround. So, consider the given code:

Program  i
Implicit None
if (<some condition>) then
  text for if block
end if  
End Program  i

if my cursor is inside (<some condition>), and do di(, in normal mode, then <some condition> will be deleted.

So, I am looking for some similar thing, when my cursor is inside if block, and I can delete text for if block!

  • 1
    so you wan't to delete "Something"? There is always this little plugin github.com/jeetsukumaran/vim-indentwise which could help you – Doktor OSwaldo Jul 16 at 9:06
  • What you do expect di to do? Because either you are talking about the deletion command d and a text object like ip 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. – statox Jul 16 at 9:15
  • @statox: :h object-select – BaRud Jul 16 at 10:02
  • 1
    With your edit now your question makes sense, thank you :) – statox Jul 16 at 10:05
  • so, can I expect some sensible answer? :p – BaRud Jul 16 at 10:11
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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