I wrote short macro that helps me grep for the word under the cursor. Here it is in my .vimrc:

let @a=":! git grep ^R^W^M"

However, when I open vim and run :reg a, I see the following:

"a   :! git grep ^R^W^M^J

You can see an ^J has been added to the macro.

If I remove the ^M in my script, then the ^J disappears also.

It seems the ^J acts similar to ^M. So, it's like I have two ^M. This isn't what I want, because I can't see the result of my command. The window just flashes before I can read it.

I have gotten my script to work by pasting and then copying it. The problem only arises when I try to load it using my .vimrc.

1 Answer 1


For whatever weird reason, it works fine if you replace the ^M^J with ^J:

:let @a=":! git grep \<c-r>\<c-w>\<c-j>"
:reg a
"a   :! git grep ^R^W^J

And @a works as expected.

(I'm using the \<...> notation since it is easier to copy paste.)

Technically, ^M is the carriage return and ^J is the newline. I'm not sure how the difference matters in this case.

  • 1
    I'll give that a shot, but how do I enter ^J? I know how to enter ^M, but not ^J. Apr 5, 2017 at 0:39
  • Oh, I understand. I'll use \<...>, then. Apr 5, 2017 at 0:40
  • @user2445507 how do you enter C-M?
    – muru
    Apr 5, 2017 at 0:41
  • ^M is entered by pressing <ctrl+v> and then <ctrl+m>. <ctrl+v> goes into some special mode that lets you write special characters that begin with ^. Apr 5, 2017 at 0:56
  • 1
    @user2445507 and that didn't work for ^J?
    – muru
    Apr 5, 2017 at 0:57

Your Answer

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

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