<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
    <title>Univers Libre - vim</title>
    <subtitle>Yet another sysadmin&#39;s personal blog</subtitle>
    <link rel="self" type="application/atom+xml" href="https://univers-libre.net/tags/vim/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://univers-libre.net"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2015-05-28T19:16:40+00:00</updated>
    <id>https://univers-libre.net/tags/vim/atom.xml</id>
    <entry xml:lang="en">
        <title>Play a Vim macro on all opened buffers</title>
        <published>2015-05-28T19:16:40+00:00</published>
        <updated>2015-05-28T19:16:40+00:00</updated>
        
        <author>
          <name>Romain</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://univers-libre.net/posts/vim-play-macro-on-all-buffers/"/>
        <id>https://univers-libre.net/posts/vim-play-macro-on-all-buffers/</id>
        
        <content type="html" xml:base="https://univers-libre.net/posts/vim-play-macro-on-all-buffers/">&lt;p&gt;Here is a small useful tip, which I use in my daily sysadmin work, when I have a
lot of similar configuration files to alter, but my modification is to
complex to be scripted with sed/awk.&lt;/p&gt;
&lt;p&gt;The perfect example is Apache’s vhost configurations in site-enabled/.&lt;/p&gt;
&lt;p&gt;Open all files in Vim and start recording your macro (with &lt;code&gt;q&lt;/code&gt;) on the first buffer.&lt;br /&gt;
Until now I opened the next buffer, replay my macro, then opened the next buffer, replay my macro again, etc…&lt;br /&gt;
Pretty boring.&lt;/p&gt;
&lt;p&gt;But I discovered recently that you can execute a command on all opened
buffers, and particularly a macro. Here is the magic line:&lt;/p&gt;
&lt;pre class=&quot;giallo z-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;:bufdo execute &amp;quot;normal @a&amp;quot;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Replace &lt;em&gt;a&lt;/em&gt; with the name of your macro of course, and don’t miss to &lt;code&gt;:write&lt;/code&gt;
at the end of your macro (or add a &lt;code&gt;| write&lt;/code&gt; at the end of the command).&lt;/p&gt;
</content>
        
    </entry>
</feed>
