Convert a search and replace to a function

2018-06-08 02:03:17

Given this search and replace expression, which works fine on one or multiple visually selected lines:

:'<,'>s/\v.{-}(`.{-}`).{-}(\\'.{-}\\').*/$this->execSQL('DELETE FROM \1 WHERE id = \2;');\r&/

I would like to stick this in a function to be call'd or mapped to a key.

Something like this works for a single line, but behaves differently on multiple lines than when I run the search and replace directly:

function! CreateDeleteStatements()

:'<,'>s/\v.{-}(`.{-}`).{-}(\\'.{-}\\').*/$this->execSQL('DELETE FROM \1 WHERE id = \2;');\r&/

endfunction

What am I looking for here?