On 03/23/2011 11:24 PM, E wrote:
Can a macro be executed while in insert mode?

The short answer is "yes, in insert-mode you can use control+O to execute one normal-mode command (such as a macro) without leaving insert-mode" ("capital-oh", not "zero" if your font doesn't distinguish that clearly)

  :help i_CTRL-O

However getting it to happen on multiple lines in Insert mode (especially in visual-block insertion mode) becomes a little tricky.

Let file equal:
     ---------------start file-----------------
     wordword word word 1
     wordword word word 2
     wordword word word 3
     wordword word word 4
     ---------------end file-------------------
Let edit goal equal:
     ---------------start file-----------------
     IF "$foo1"<>"" wordword word word 1
     IF "$foo2"<>"" wordword word word 2
     IF "$foo3"<>"" wordword word word 3
     IF "$foo4"<>"" wordword word word 4
     ---------------end file-------------------
I am sure others have begun using a  macro instead of using a
"substitute regex" because it is easier and or quicker but
then find that the free-form "off the hip" method is a dead
end.

I'm one of the regexp folks, so I'd just do

  :%s/.*\s\(\d\+\)$/IF "$foo\1"<>"" &

rather than trying to jockey the creation of a macro that works in insert mode, correctly picks off numbers at the end of the line (especially if they stretch to multiple digits), and leaves me where I expect it to (both positionally and in the desired mode).

-tim






--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to