I'm trying to search for the selected line of a file using the following:
function! GrepSelection() normal! gvy let result = escape(@", '\\/.*$^~#') let result = substitute(result, "\n$", "", "") let result = substitute(result, "\n", '\\n', "g") new | setlocal buftype=nofile bufhidden=hide noswapfile execute 'grep "'.result.'" file' endfunction xnoremap <silent> <unique> * :<C-U>call GrepSelection()<CR>
but it seems it fail when i replace the
execute part with
read ! (it also fail with
read!). Yet it does work when i do this manually on the commandline.
The way it fail is:
/bin/bash: grep ".result." file: No such file or directory
where it obviously does find the file, but the problem here is the fact that ".result." is taken literally, instead of being replaced with the selected string (like when
execute is used instead).
Anything wrong with what I'm doing here?