Non greedy and a fixed number of characters search and replace in VIM
<p>I have a number of strings which are something like this - </p>

<pre><code>icon=null restored=0 title=Adblock Browser itemType=0 container=-101
</code></pre>

<p>I want to replace every string after the <code>=</code> such that there is a <code>|</code> separating two fields.</p>

<p>In the above example, I want the string to be replaced to -</p>

<pre><code>icon=null |restored=0 |title=Adblock Browser |itemType=0 |container=-101
</code></pre>

<hr>

<p>In VIM, I was trying the following <code>search-and-replace</code> expression - </p>

<pre><code>:%s/=.\{-} \?.\{-} /\0|/gc
</code></pre>

<p>However, the problem here is that, it doesn't match <code>=Adblock Browser</code>, it <strong><em>only matches</em></strong> the <code>=Adblock</code> part.</p>

<hr>

<p>About the part where I am using the <code>.\{-}</code> is because sometimes the strings are like this - </p>

<pre><code>icon=null profileId=0 screen=0 modified=1462258474716 iconPackage=null iconResource=null spanX=1 cellX=2 displayMode=null appWidgetProvider=null intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.play.games/com.google.android.gms.games.ui.destination.main.MainActivity;end restored=0 title=Play Games itemType=0 container=8 iconType=null isShortcut=null spanY=1 _id=14 cellY=1 uri=null appWidgetId=-1
icon=null profileId=0 screen=1 modified=0 iconPackage=null iconResource=null spanX=1 cellX=3 displayMode=null appWidgetProvider=null intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.android.vending/.AssetBrowserActivity;end restored=0 title=Play Store itemType=0 container=-100 iconType=null isShortcut=null spanY=1 _id=15 cellY=3 uri=null appWidgetId=-1
icon=null profileId=0 screen=4 modified=0 iconPackage=null iconResource=null spanX=1 cellX=4 displayMode=null appWidgetProvider=null intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package=org.adblockplus.browser;component=org.adblockplus.browser/.App;end restored=0 title=Adblock Browser itemType=0 container=-101 iconType=null isShortcut=null spanY=1 _id=19 cellY=0 uri=null appWidgetId=-1
</code></pre>

<p>and the output should be like this - </p>

<pre><code>icon=null |profileId=0 |screen=0 |modified=1462258474716 |iconPackage=null |iconResource=null |spanX=1 |cellX=2 |displayMode=null |appWidgetProvider=null |intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;component=com.google.android.play.games/com.google.android.gms.games.ui.destination.main.MainActivity;end |restored=0 |title=Play Games |itemType=0 container=8 |iconType=null |isShortcut=null |spanY=1 |_id=14 |cellY=1 |uri=null |appWidgetId=-1
</code></pre>

<p>and similar for other strings.</p>

<hr>

<h2>Minimal, Verifiable example</h2>

<p>This is the content of the input file -</p>

<pre><code>icon=null profileId=0 screen=4 modified=0 iconPackage=null iconResource=null spanX=1 cellX=4 displayMode=null appWidgetProvider=null intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package=org.adblockplus.browser;component=org.adblockplus.browser/.App;end restored=0 title=Adblock Browser itemType=0 container=-101 iconType=null isShortcut=null spanY=1 _id=19 cellY=0 uri=null appWidgetId=-1
</code></pre>

<p>The search-and-replace expression in VIM -</p>

<pre><code>:%s/=.\{-} \?.\{-} /\0|/gc
</code></pre>

<p>The Output: </p>

<pre><code>icon=null |profileId=0 |screen=4 |modified=0 |iconPackage=null |iconResource=null |spanX=1 |cellX=4 |displayMode=null |appWidgetProvider=null |intent=#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package=org.adblockplus.browser;component=org.adblockplus.browser/.App;end |restored=0 |title=Adblock |Browser itemType=0 |container=-101 |iconType=null |isShortcut=null |spanY=1 |_id=19 |cellY=0 |uri=null |appWidgetId=-1
</code></pre>

<p>Erroneous part - </p>

<pre><code>restored=0 |title=Adblock |Browser itemType=0 |container=-101 |
</code></pre>

<p>should have been - </p>

<pre><code>restored=0 |title=Adblock Browser |itemType=0 |container=-101 |
</code></pre>