I often re-direct my terminal output to vim, in this fashion, which I get tired of typing all the time:
ls | vim –
I would like to define a function v to do this for me, i.e I want to be able to type:
v ls and that this somehow ‘expands’ to the previous command.
I can do this do work in simple cases with a script in this kind (of course, this can be re-factored as a small function):
while (( “$#” )); do
echo -n $1 >> crrt_cmd
echo -n ” ” >> crrt_cmd
chmod +x crrt_cmd
bash crrt_cmd | vim –
This works fine for very simple commands, for example ls or ls -l, but it does not work at all when some piping is present for example.
Any idea on how to perform something similar, but that works with any valid bash command?
So just to be clear, I would like things to work in this way if it is possible:
v ls | grep keyword | head -5
would translate into:
ls | grep keyword | head -5 | vim –