Martin Wang
Martin Wang

Reputation: 1007

How to input ^M in vim when ctrl-v is used as paste

My vim used ctrl-v as paste short-cut, which conflict with commands need ctrl-v as shortcut prefix.

For example, ^M need ctrl-v ctrl-m. I can do that in vim command line, and vim without intialization. But the symbol won't go to buffer from vim command line. :s/aaa/^M/g doesn't work.

Although, I can use echo -e "\r" or no-initialized vim to work around it.

But how to type this symbol in my current vim configuration?

Upvotes: 3

Views: 5727

Answers (3)

user188276
user188276

Reputation:

try Ctrl-Q Enter

(This solution also works when you try to enter digraphs by number in Vim)

Upvotes: 1

mMontu
mMontu

Reputation: 9273

You could try using a mapping to the original function of ctrl-v:

noremap! <C-Q>  <C-V>

But as explained on :h CTRL-V-alternative and noted by ZyX on the comments, your issues may be that your terminal is capturing the ctrl-q (more details here). If the mapping above doesn't works you could try mapping to something else:

noremap! <leader><C-V>  <C-V>

Then hitting leader (usually \) followed by ctrl-v ctrl-m should insert ^M on both insert and command mode.

Upvotes: 1

Kent
Kent

Reputation: 195169

to input ^M you can try followings:

  • Ctrl-V Enter
  • Ctrl-V Ctrl-M
  • use digraph Ctrl-K C R, C R means CR.

Upvotes: 4

Related Questions