Vim Tips Wiki
(Move categories to tip template)
(Change <tt> to <code>, perhaps also minor tweak.)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=1010
 
|id=1010
 
|previous=1009
 
|previous=1009
|next=1011
+
|next=1012
|created=October 6, 2005
+
|created=2005
 
|complexity=basic
 
|complexity=basic
 
|author=Frans
 
|author=Frans
|version=5.7
+
|version=6.0
 
|rating=-2/4
 
|rating=-2/4
|category1=
+
|category1=Text processing
|category2=
+
|category2=Usage
 
}}
 
}}
Our current development requires everything to be MISRA compliant. One of the MISRA rules is: <tt>//-style-comments</tt> are not acceptable. These occurrences must be replaced by <tt>/*-style-comments-*/</tt>. The following mapping will do this per line.
+
Developers and users will often have a need to change one pattern of text to match a different pattern. This can be completed using a key map and a regular expression. For example some development requires developers to be MISRA compliant. One of the MISRA rules is <code>//-style-comments</code> are not acceptable. These occurrences must be replaced by <code>/*-style-comments-*/</code>. Adding the following mapping to the vimrc file will do this per line.
 
 
<pre>
 
<pre>
:map &lt;F5&gt; /\/\/&lt;enter&gt;xxi/*&lt;esc&gt;A*/&lt;esc&gt;
+
:map <F5> /\/\/<CR>xxi/*<Esc>A*/<Esc>
 
</pre>
 
</pre>
   
This will do the action per found line. Start at the beginning of the file, and repeatedly press &lt;F5&gt; (or whatever key you use) untill an error message occurs.
+
This will do the action per found line. Start at the beginning of the file, and repeatedly press <F5>. Alternatively, this regular expression can be used:
 
==Comments==
 
This will help you:
 
 
 
<pre>
 
<pre>
%s,//\(.*\),/*\1 */,
+
:map <F5> %s,//\(.*\),/*\1 */,
 
</pre>
 
</pre>
   
 
==Comments==
----
 

Latest revision as of 06:03, 13 July 2012

Tip 1010 Printable Monobook Previous Next

created 2005 · complexity basic · author Frans · version 6.0


Developers and users will often have a need to change one pattern of text to match a different pattern. This can be completed using a key map and a regular expression. For example some development requires developers to be MISRA compliant. One of the MISRA rules is //-style-comments are not acceptable. These occurrences must be replaced by /*-style-comments-*/. Adding the following mapping to the vimrc file will do this per line.

:map <F5> /\/\/<CR>xxi/*<Esc>A*/<Esc>

This will do the action per found line. Start at the beginning of the file, and repeatedly press <F5>. Alternatively, this regular expression can be used:

:map <F5> %s,//\(.*\),/*\1 */,

Comments[]