Automate write for loop in vim?

I keep writing for loops today. They all have the format:

for(size_t szI = X; szI < Y; ++szI)
{
   //Something
} 

And I know that 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 as soon as I put X and Y in some way?

+3
source share
4 answers

You can use a plugin like snipMate to store fragments, which you can then save in a fragment for.

In fact, it already comes with a lot of predefined snippets , many of which may prove useful.

+7
source

Vim wiki :

:abbreviate forl for (int i = 0; i < ; i++) {<esc>7hi

, , .

+1

:

let @f = "ifor(size_t szI = X; szI < Y; ++szI)^M{^M}^[O^T"

, ^X Ctrl V Ctrl X.

@f.

Edit: I just saw the second part of your question (not sure if you edited it? Maybe I'm wrong.), But if X and Y change, I would suggest a more efficient solution like snipMate.vim.

+1
source

The most developed way is to really use the fragment mechanism. snipMate has been called.

I support mu-template , which is the root of extended snippets from LH castes .

+1
source

Source: https://habr.com/ru/post/1785891/


All Articles