inoremap  :s/s*([=+!-]?=)s*/ 1 /ge:noho

=、==、!=、+ =、 –

inoremap  :s/s*([=+!-]?=|[><]=?)s*/ 1 /ge:noho

After this change, neither assignment, nor comparison operators
are matched anymore (no errors, just nothing happens). However,
searching for this new pattern in vim directly highlights all of
them. I’m not sure if the issue is due to < and > being
special characters in .vim files (used for , etc.), I tried
escaping them with , but that didn’t seem to help. Also, when I
put them inside the same block as the rest of the operators, they
work fine:

inoremap  :s/s*([=+!-><]?=)s*/ 1 /ge:noho

The only problem in this case, however, is that if I type
something like xx = (a+b+c+d+e+f) - (g+h+i) rather
than x = (a + b + c + d + e + f) - (g + h + i)).
Likewise, I don’t want my negations to look like if( !
(statement) ...
. What am I doing wrong? Also, I’m using vim
7.2.245. Thanks


正規表現で magic の量を具体的に指定してみてください:

inoremap  amz:-1s/vs*([=+!-<>]?=|[<>])s*/ 1 /ge:nohls`zcl

Note also, I employed C-o to issue the substitute
from insert mode


  • a execute the Enter as normal, insert a
    dummy character ('a')
  • leave insert mode
  • mz save cursor position in register
  • :-1s/v.../.../g on the previous line
    (-1) perform a global substitution with
    very-magic on
  • :nohls hide search highlighting
  • `z restore saved cursor position
  • cl enter insert mode, overwriting the earlier
    dummy character


メールアドレスが公開されることはありません。 * が付いている欄は必須項目です