Escape newlines for g*/g# searches

Extract code to a function and handle newlines so you can select several
lines and search.

For some reason the obvious method of substituting literal newlines with newline
escape sequences doesn't work, so I split and join instead.

Since I'm searching from a function, I need to modify searchforward for
reverse search. (Could return a value and search from the map instead
but that seems like it would be messier?)