2

I was thinking of setting my registers to equal common coding techniques. For example, I was thinking of doing this:

:let @i = "int i=0;"

Then I would set f for for loop, w for while loop etc. Is this a bad technique or is there a better way of doing this?

ib.
  • 25,324
  • 10
  • 71
  • 97
Brandon Ling
  • 3,480
  • 6
  • 28
  • 46

2 Answers2

7

I think that you could use snippets instead. Try to look at snipmate plugin http://www.vim.org/scripts/script.php?script_id=2540

You can just type "inti TAB" and it'll expand to "int i=0;" if you wish.

It already has a lot of snippets to many languages but you can configure it to do what you want.

ARibas
  • 86
  • 1
3

For simple expansions, the built-in abbreviations will suffice:

:iab ii int i=0;

If you want parameter expansion, different "stops" to fill in data, and other advanced features, various snippets plugins (on http://www.vim.org/) offer this functionality; one of the first and broadly used ones is snipMate.

Ingo Karkat
  • 154,018
  • 15
  • 205
  • 275