How do I speed up macro execution and bulk operations by preventing screen redraws?
Answer
:set lazyredraw
Explanation
When Vim runs a macro or an :argdo / :bufdo loop, it redraws the screen after every command by default. Setting lazyredraw tells Vim to skip screen redraws during command execution and only update the display once the macro or script finishes. The result is dramatically faster execution and a cleaner experience for long-running operations.
How it works
:set lazyredraw(abbreviated:set lz) enables lazy redraw mode- While active, Vim skips intermediate screen updates during macros and Ex command sequences
- The display is refreshed once the operation completes
:set nolazyredraw(or:set nolz) reverts to immediate redraw- You can add it to your vimrc permanently or toggle it on before long operations
Example
Running a macro that touches 500 lines is noticeably faster with lazyredraw:
:set lazyredraw
500@q
:set nolazyredraw
Or keep it on globally in your vimrc:
set lazyredraw
Tips
lazyredrawis especially impactful on slow terminals or when running Vim over SSH- Some plugins that use frequent screen updates may behave oddly with
lazyredrawalways on — toggle it around specific operations if you notice display issues - Related option:
ttyfast(:set ttyfast) hints to Vim that the terminal connection is fast and can receive many characters; useful for the opposite situation (fast local terminal, keep redraws smooth) :redraw!forces an immediate full screen refresh when you need it mid-script