Suppose I am using vim with two or more files opened in split-screen mode. The open files are very similar, and I want to perform a few identical changes to all files.

I already know of

:windo set scrollbind

to have the windows scroll in the same way.

My question is the following: is there a method to enter insert mode in all windows. Or, if not, to copy all latest actions to a different window. The result should be that some edit is the same in all open files.


You can record your editing commands in a macro (e.g. register Q via qq...q), and then replay that macro in all other windows. If you :close the first window that already got the treatment, you can use

:windo normal! @q

for that.

You need to be careful to only use movements and text objects that are valid in all buffers (as Vim will beep and abort a macro replay on error), so this will only work on very similar buffers and a bit of forethought. Best start the macro from a predefined position, e.g. via gg0 or a /search.

The :substitute command (possibly with the /c flag to query on each match) can be a great alternative to normal mode commands, and can be combined / included in a macro.

  • Awesome, never took time to understand macros, but know I get why they are useful. – Bernhard Jan 7 '14 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.