Say I want to search for multiple lines (or do anything with them in the command line).

I yank some lines and enter search mode (/).

I press Ctrl + r" to paste what I just yanked, but I get ^M for the line breaks so the search is unsuccessful unless I change the ^M to \n.

This is on ubuntu using awesomewm and st terminal. I suspect it could be an issue with my terminal as opposed to vim.

Here is a gif illustrating this:

Here is a gif illustrating this

1 Answer 1


You can edit the contents of the register like this to escape the newlines:

:let @0=substitute(@0, '\n', '\\n', 'g')

And then just do your command like normal using Ctrl-R.

I rarely run into this use case so I guess this is good enough, but I still don't understand why vim behaves like this so would be great if someone else has a better solution.

You could add this to a function in your vimrc to do the substitution and then search if you liked, but I prefer not to add too much custom stuff so that when I log onto other systems I don't need to depend on having my vimrc.

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.