Substitute with contents of register or lines range from elsewhere in file in Vim

Viewed 10753

I'm using Vim, and I want to substitute some placeholder text with a long string, that spans several lines, which is already written somewhere else in the file.

Is it possible to replace a pattern with the contents of a register? Something like

:%s/foo/<contents of register A>

Otherwise, is it possible to replace with a range of lines? something like

:%s/foo/<content of lines from 10 to 15>
2 Answers
:%s/foo/\=getline(10, 15)/g

:%s/foo/\=join(getline(10, 15))/g
Related