Vim macros: insert mode

I am trying to create an insert macro if, when entering the @f command, it should print a for loop. I got this piece of work. However, I would like to leave the user in insert mode until the first semicolon. I tried to leave the last command before exiting the record as β€œa” to add, but this did not work. Any suggestions?

+6
source share
2 answers

You can use <Co>q to end recording in insert mode. <Co> In insert mode, you can execute one command in normal mode and then return to insert mode (see :help i^O ).

+11
source

I think the answer is to use abbreviations. For example: iabbrev @f for(; ; )<CO>4<Left> Then, in insert mode, type @f and after you press Space after it, the reduction will be performed, and you will get for( *; ; ) @f for( *; ; ) , where * will display the cursor.

+1
source

All Articles