Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I prevent changing buffer when using the :bufdo command?

Tags:

vim

This command replaces some text in all my buffers:

:bufdo %s/some_text/other_text/ge | update

When running this command, the buffer of the current window is changed to the last buffer affected by :bufdo, as explained in :help :bufdo:

The last buffer (or where an error occurred) becomes
the current buffer.

I know it's possible to prevent the buffer from being changed, but I don't remember how.

like image 228
Hubro Avatar asked Mar 19 '23 01:03

Hubro


1 Answers

You can save off the current buffer before running the command, then jump to it after:

:let buf=bufnr('%') | exec 'bufdo some_command' | exec 'b' buf
like image 163
Ben Avatar answered Apr 09 '23 19:04

Ben