I'm trying to remove instances of the following:

add $t1, $zero, 9
sw $t1, 8($t4) 

Where 9 could be any number, however 8 is consistent. If I copy this expression in Vim I get: ^Iadd $t1, $zero, 9^M^Isw $t1, 8($t4)^M

Of course if I want to search and replace (I do) I need to escape the $. I've also tried replacing ^I with \t and ^M with \r, but can't seem to match this expression. I've tried:

%s/\tadd \$t1, \$zero, \d\r\tsw \$t1, 8(\$t4)//
%s/^Iadd \$t1, \$zero, 9^M^Isw \$t1, 8(\$t4)^M//
%s/\tadd $t1, $zero, 9\r\tsw $t1, 8($t4)//

but I can't seem to get anything to match. What am I missing here? Pretty much everything in assembly (MIPS) looks the same, so solving this problem would be quite useful

I have also tried the following:enter image description here

enter image description here

1 Answer 1


I would recommend using very magic mode for such searching. ^M is actually \n, not \r. I don't see tabs in the provided excerpt, but this seems to work (without tabs):

\vadd \$t1, \$zero, \d\nsw \$t1, 8\(\$t4\)

You can add those \t if they're present in your text.

  • I tried that, but didn't seem to work. Posted screenshot results in questions. Also, when do you use \n and when use \r? Cause usually if I want to write something for search and replace I'll use \n for new line, but if I'm trying to match a text I use \r
    – luca590
    May 7, 2017 at 15:38
  • 1
    So maybe try to set hlsearch and set incsearch - this will make search more interactive, it will show you in real time if your search expression matches and what it matches. I test more complex patterns this way.
    – grodzik
    May 7, 2017 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.