Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim macro very slow

Tags:

text

vim

I'm saving a very simple vim macro to a key: qa$pjq and then executing it 40000 times with 40000@a. This is very slow. I must be doing something wrong, because while it does work it takes something like 60-90 seconds. Is this as fast as vim goes? Are there some settings that can accelerate this? Is there a mixture of plugins that make macro execution slow?

I'm using a Mac and using MacVim. It is a plain text file, it really doesn't get any simpler than this.

like image 792
carlosdc Avatar asked Dec 05 '11 03:12

carlosdc


3 Answers

It doesn't take long to paste 40,000 lines, but if you've got the screen constantly updating as you often do in a macro that slows things down.

First, a question about what your macro is supposed to be doing. If it's simply pasting contents of default register, then proper macro definition is just qapjq. There is no need to position the cursor in a specific spot on previous line. [EDIT: sorry, I was assuming you were doing linewise paste, positioning is needed if you're pasting character-wise register at end of line. . .. ]

Second, you can speed up your current macro by setting lazyredraw (:set lazyredraw), so screen doesn't update as it goes. Probably won't speed things up a whole lot, keyboard macros like this aren't like direct processing of the buffer.

Third, here's another method that should take about a second: .,+40000g/.*/normal! $p

like image 99
Herbert Sitz Avatar answered Nov 15 '22 23:11

Herbert Sitz


This is normal. As Herbert Sitz wrote, updating the screen is slow.

You might want to just run a substitution command: :.,+40000s/.*/&<c-r>".

  • .,+40000 is a range including the current line and the 40000 following
  • .* in the pattern matches a whole line
  • & in the string is the line that was matched
  • <c-r>" pastes the contents of the unnamed register
like image 29
Don Reba Avatar answered Nov 15 '22 21:11

Don Reba


I would recommend to start a blank vim with 'vim -u NONE '. Often plugins are slowing down things. You will see that it works much faster this way. Then you need to find out what plugin causes this slowdown. See also How to see which plugins are making Vim slow?

like image 8
Hans Dampf Avatar answered Nov 15 '22 21:11

Hans Dampf