Reputation: 14413
I keep writing for loops today. All of them have the format :
for(size_t szI = X; szI < Y; ++szI)
{
//Something
}
And I know there are ways to record actions in vim. If X and Y can change, can I do something in vim to write a for loop once I supply X and Y somehow?
Upvotes: 4
Views: 1692
Reputation: 32926
The most evolved way is indeed to use an snippets engine. snipMate has been evoked.
I'm maintaining mu-template that is the root of the advanced snippets from lh-cpp.
Upvotes: 1
Reputation: 40927
I'd use a macro:
let @f = "ifor(size_t szI = X; szI < Y; ++szI)^M{^M}^[O^T"
Note all ^X
characters are entered via CtrlVCtrlX.
You can then run this macro with @f
.
Edit: Just saw the second part of your question (not sure if you edited it? Maybe I read wrong.) but if X and Y are going to change, I'd suggest a more featured solution such as snipMate.vim.
Upvotes: 1
Reputation: 50858
You can use a plugin like snipMate to store snippets, which you can then store a for
snippet in.
In fact, it already comes with a lot of predefined snippets, a lot of which may prove useful.
Upvotes: 7
Reputation: 15560
This is one example from Vim wiki on abbreviations:
:abbreviate forl for (int i = 0; i < ; i++) {<esc>7hi
Not exactly what you wanted, but close to that.
Upvotes: 1