I have a file called Index.txt
with the following lines:
/Project/A/B/C/D/main.c
/Project/A/B/C/D/main_backend.c
/Project/A/B/C/D/main_frontend.c
I'd like to create a command called Fsearch
to execute a search in Index.txt
using regular expressions, match the first occurrence and execute :vsplit
with it. For example, if I execute:
:Fsearch main_backend.c
Vim should execute:
:vsplit /Project/A/B/C/D/main_backend.c
and If I execute:
:Fsearch main*.c
Vim should execute:
:vsplit /Project/A/B/C/D/main.c
This is what I've tried so far but I'm pretty sure it could be improved:
function! CopyMatches(reg)
let l:file = grep -m 1 a:reg ~/Index.txt
echom l:file
if len(l:file) > 0
exec ':vsp ' . l:file
else
echom 'File not found: ' . l:file
end
endfunction
command! -nargs=* Fsearch call CopyMatches('<args>')
Any suggestion?