get bash history to vi

前端 未结 5 984
故里飘歌
故里飘歌 2021-02-19 04:57

When I try to read bash history into vim, I get nothing.

:r !history

If I just execute the command, i.e.

:!history
5条回答
  •  暖寄归人
    2021-02-19 05:57

    :r!echo "history" | bash -i 2>/dev/null | sed -e 's/\x1b\[.//g'
    

    Explanation:

    The history command only works on interactive shell.

    The first part:

    echo "history" | bash -i 2>/dev/null
    

    Forces interactive shell (and removes lines which aren't output of history).

    The second part:

    sed -e 's/\x1b\[.//g'
    

    Removes escape character the shell might output (happened on my system).

提交回复
热议问题