7

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

8

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.
5

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

1

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.

0

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

0

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)

:%s/[^KNU^KCR]//g

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

:dig

To see how to define your own see

:help :dig

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .