This is an interesting problem, with several parts. First we'll need a
r.e matching constants:
is a first approximation; it misprocesses strings with internal "'s and
scientific notation numeric constants and doesn't even try for
non-decimal radix constants.
Then we need an r.e matching a variable name:
is an approximation. Then we combine these with the three classes of
relational operators: = & !=; < & <=; and > & >=, separately since they
must be treated differently:
:%s/\([A-Za-z_][A-Za-z_0-9}* \)[ ^I]*\(!+=\)
:%s/\([A-Za-z_][A-Za-z_0-9}* \)[ ^I]*<\(=+\)
:%s/\([A-Za-z_][A-Za-z_0-9}* \)[ ^I]*>\(=+\)
Each of the above pairs of lines represent a single long line to vim.
Note that all spaces around the relational operators have been taken
out; if you want a single space on either side them:
/\3 \2 \1/
will put them there for you.
While this will handle most simple cases, it does not even attempt to
handle the more complex cases where there are expressions involved (on
As usual, this composed extemporaneously, therefore trst carefully bfore
committing to real data.
> In C/C++ the following style of check is preferred :
> VALUE <relational operator> VARIABLE
> instead of
> VARIABLE <relational operator> VALUE
> if( 5 == data ) is preferred over
> if( data == 5
> while( CONST_NAME != value ) is preferred over
> while( value != CONST_NAME)
> I have do the above suggested changes throughout the file.
> How do I do it using vim ?