I am trying to create an insert macro where if I type in the command @f it should print out a for loop. I got that part working. However, I would like to leave the user in insert mode before the 1st semicolon. I tried to leave the last command before I quit the record as 'a' for append, but that did not work. Any suggestions?
To go into INSERT mode from COMMAND mode, you type i . To go back to COMMAND mode, you type the esc key. vim starts out in COMMAND mode. Over time, you will likely spend more time in COMMAND mode than INSERT mode.
Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode. Type :wq to save and exit your file.
6) actually persists macros and named buffers automatically (by default, although I haven't looked for a way of turning this behavior off). Closing a Vim session will update the ~/. viminfo file with any named buffers / macros.
You can use <C-o>q
to finish recording while in insert mode. <C-o>
in insert mode allows you to execute one command in normal mode, and then returns to insert mode (see :help i^O
).
I think the answer is to use abbreviations. For example:
iabbrev @f for(; ; )<C-O>4<Left>
Then in insert mode type @f
and when you hit Space
after it, the abrevation will be executed and you will got a for( *; ; )
, where the *
signs the cursor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With