Wikia

Vim Tips Wiki

Changes: Add html tags with substitute

Edit

Back to page

(Move categories to tip template)
(Remove html character entities)
 
Line 21: Line 21:
 
</pre>
 
</pre>
   
To generate html tags of form &lt;td&gt;1&lt;/td&gt; use command:
+
To generate html tags of form <td>1</td> use command:
 
<pre>
 
<pre>
:%s/\(\s\+\)\(\d\+\)/&lt;td&gt;\2&lt;\/td&gt;/g
+
:%s/\(\s\+\)\(\d\+\)/<td>\2<\/td>/g
 
</pre>
 
</pre>
   
 
The result:
 
The result:
 
<pre>
 
<pre>
&lt;td&gt;1&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;55&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;
+
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
&lt;td&gt;1&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;55&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;
+
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
&lt;td&gt;1&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;55&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;
+
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
&lt;td&gt;1&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;55&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;
+
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
&lt;td&gt;1&lt;/td&gt;&lt;td&gt;12&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;55&lt;/td&gt;&lt;td&gt;67&lt;/td&gt;
+
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
 
</pre>
 
</pre>
   
 
To generate words like:
 
To generate words like:
 
<pre>
 
<pre>
&lt;td&gt;uma&lt;/td&gt;&lt;td&gt;porção&lt;/td&gt;&lt;td&gt;de&lt;/td&gt;&lt;td&gt;palavras&lt;/td&gt;&lt;td&gt;para&lt;/td&gt;&lt;td&gt;testes&lt;/td&gt;&lt;td&gt;deve&lt;/td&gt;
+
<td>uma</td><td>porção</td><td>de</td><td>palavras</td><td>para</td><td>testes</td><td>deve</td>
&lt;td&gt;ser&lt;/td&gt;&lt;td&gt;digitada&lt;/td&gt;&lt;td&gt;após&lt;/td&gt;&lt;td&gt;isto&lt;/td&gt;&lt;td&gt;coloque&lt;/td&gt;&lt;td&gt;espaço&lt;/td&gt;&lt;td&gt;no&lt;/td&gt;
+
<td>ser</td><td>digitada</td><td>após</td><td>isto</td><td>coloque</td><td>espaço</td><td>no</td>
&lt;td&gt;inicio&lt;/td&gt;&lt;td&gt;de&lt;/td&gt;&lt;td&gt;cada&lt;/td&gt;&lt;td&gt;linha&lt;/td&gt;
+
<td>inicio</td><td>de</td><td>cada</td><td>linha</td>
 
</pre>
 
</pre>
   
Line 45: Line 45:
 
<pre>
 
<pre>
 
:%s/^/ /g
 
:%s/^/ /g
:%s/\(\s\+\)\(\S\+\)/&lt;td&gt;\2&lt;\/td&gt;/g
+
:%s/\(\s\+\)\(\S\+\)/<td>\2<\/td>/g
 
</pre>
 
</pre>
   
 
==Comments==
 
==Comments==
 
<pre>
 
<pre>
:%s,\(\d\+\),&lt;td&gt;\1&lt;/td&gt;,g
+
:%s,\(\d\+\),<td>\1</td>,g
 
</pre>
 
</pre>
   

Latest revision as of 00:14, September 30, 2008

Tip 1319 Printable Monobook Previous Next

created September 4, 2006 · complexity basic · author Sérgio Luiz Araújo Silva · version 6.0


Suppose you have a table of numbers like:

1 12 3 13 11 55 67
1 12 3 13 11 55 67
1 12 3 13 11 55 67
1 12 3 13 11 55 67
1 12 3 13 11 55 67

To generate html tags of form <td>1</td> use command:

:%s/\(\s\+\)\(\d\+\)/<td>\2<\/td>/g

The result:

<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>
<td>1</td><td>12</td><td>3</td><td>13</td><td>11</td><td>55</td><td>67</td>

To generate words like:

<td>uma</td><td>porção</td><td>de</td><td>palavras</td><td>para</td><td>testes</td><td>deve</td>
<td>ser</td><td>digitada</td><td>após</td><td>isto</td><td>coloque</td><td>espaço</td><td>no</td>
<td>inicio</td><td>de</td><td>cada</td><td>linha</td>

use commands:

:%s/^/ /g
:%s/\(\s\+\)\(\S\+\)/<td>\2<\/td>/g

CommentsEdit

:%s,\(\d\+\),<td>\1</td>,g

Around Wikia's network

Random Wiki