How do I insert C/C++-type loops and statements templates automatically in Vim?

closed as too broad by Tumbler41, Herb Wolfe, peterh, jamessan, jalanb Dec 7 at 3:12

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • are you looking for snippets plugins? – Christian Brabandt Dec 5 at 7:32
  • 3
    Please edit your question and give us more details about what you want: What do you mean by "loops and statements"? What do you want your loop to look like for example? How to do you want to insert it? What do you mean by "automatically"? Have you tried something? What didn't work? If you don't tell us precisely what you are looking for nobody will be able to help you. If you can't edit your question we'll have to close it as being too broad because there is no point keeping questions that nobody can answer and nobody can learn from. – statox Dec 5 at 10:07
  • @ChristianBrabandt After having read Luc's answer below, yes, snippets plugins (which I'd never heard of before) does seem to be what I'm looking for. – Geremia Dec 5 at 17:16
  • 2
    Possible duplicate of What is the difference between the vim snippets plugins? – Geremia Dec 6 at 15:21
up vote 1 down vote accepted

There exist many ways to define snippets for control statements: via abbreviations or via snippets. I remember a Q/A about abbreviations versus snippet plugins.

TL;DR: We can achieve the same things with both. The main difference is that snippet plugins provide a much simpler way to define maintainable code snippets.

For instance, in my lh-cpp plugin you could find some truly complex abbreviation definitions of control-statement code snippets, and also code snippet definitions for my mu-template plugin, plus many truly advanced skeletons/snippets and wizards for C++. c.vim plugin provides other snippets and abbreviations.

Most snippet plugin users prefer snipmate & co over mu-template and lh-cpp.

  • Im not sure about the wording of the last sentence: I might write « snipmate & co. are popular options » to avoid making a generalization about vim users. I don’t use snippets at all, others dont use plugins, still others set compatible. I don’t think you intended such a generalization, just trying to suggest a clarification to avoid it. – D. Ben Knoble Dec 5 at 18:29
  • @D.BenKnoble, Thank. Is my edit enough to clarify my though? – Luc Hermitte Dec 5 at 18:33
  • I think my biggest issue is with the wording « most vim users », since it seems to make assumption about the way people use vim. But I see how you clarified that it is a preference for one over another and I can live with that. – D. Ben Knoble Dec 5 at 18:47
  • 1
    @D.BenKnoble. I see, I hope it's better now ^^ – Luc Hermitte Dec 5 at 18:48

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