I'm using grep in vim to do something such as:
:grep pattern file
and have a key-map for it that looks like that:
function! Escaped()
call inputsave()
let result = escape(@", '\\/.*$^~[]#')
let result = substitute(result, "\n$", "", "")
let result = substitute(result, "\n", '\\n', "g")
call inputrestore()
return result
endfunction
xnoremap <silent> <unique> * y:grep "<C-r>=Escaped()<CR>" file
This does work great but I want to open the result of this command in a split window instead.
I tried inserting sp
, split
and such at the start of the command, or before grep, but it doesn't seem to work.
Quickfix does seem to work, but since it keeps old matches I would prefer for it to be either deleting the old match, or (as the question suggests) opening the result in a split window in vim (without tmux etc)
How could I do that?
:grep
opens its result on the Quickfix window, so it's already a split window in a way... You mention the Quickfix in "I would prefer for it to be either deleting the old match", which I don't really understand what you mean by it... Can you give an example that illustrates what you want to do with it? – filbranden♦ Sep 5 '20 at 1:29:split | grep pattern file
? (Or:snew
as the first command?) This would create a split first, then run your grep. – filbranden♦ Sep 5 '20 at 1:42<Bar>
– D. Ben Knoble♦ Sep 5 '20 at 14:26