I copied some data from an app and it has lots of ^Ds and ^Ms in it. I got rid of ^D with no problem using :%s/^D//g and I know I can remove ^M with something like :%s/^V^M//g but the problem is that I'm running on windows and ^V is Ctrl-V, which pastes data from the clipboard into gvim. How do I escape the paste function of ^V/ctrl-V in Windows for vim?

5 Answers 5


from :help CTRL-V-alternative:

                                                *CTRL-V-alternative* *CTRL-Q*
Since CTRL-V is used to paste, you can't use it to start a blockwise Visual
selection.  You can use CTRL-Q instead.  You can also use CTRL-Q in Insert
mode and Command-line mode to get the old meaning of CTRL-V.  But CTRL-Q
doesn't work for terminals when it's used for control flow.

Another Way, specific for ^M, would be to use :%s/\r//g since ^M is a carriage return.


To use your familiar MS Windows hotkeys for copy, paste etc. use the mswin.vim file as your configuration. Copy it from your install path to where your $HOME directory is, renamed to _vimrc. Type :echo $HOME to figure out where that is. Usually something like C:\Users\'username'. Restart gVim and your regular Windows Ctrl-V, Ctrl-C type of hotkeys should work.

See Where should the .vimrc file be located on Windows 7? for a little more guidance.


Please use :%s/\r/**\r\l**/g. This will convert your carriage return to Windows style carriage return + line feed combination.


I've had the same problem with vi inside conemu and other programs which interrupt keystrokes and replace them with other actions.

I got around this by using ^K (Ctrl-K) to enter a digraph for the search and replace.

For example I wanted to remove NUL (0x00) characters and CR (^M or 0xd) characters

Normally I would Use ^V000 and ^V^M however with the default digraphs defined you can use the following (note ^K is pressing Ctrl and K)


If those digraphs are not working you can see the currently set ones with


To see how to define your own see

:help :dig

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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