Is it possible to achieve the following

➜ ag editNote                    
8:const editNote = ({ commit }, e) => {
26:  editNote,

5:      @input="editNote"
22:      'editNote',

/frontend on  master [✘!?] 
➜ vi Ed    

For example I would like to start typing vi Edit and get this replaced with

vi src/components/Editor.vue

  • I don’t think it’s possible on ZSH, but maybe with Bash...
    – Stan Strum
    Commented Jan 30, 2018 at 2:39

1 Answer 1


The shell, whether bash or zsh, does not have access to the terminal scroll back buffer. While ag was running, output from it goes direct to the terminal and can't be intercepted by the shell.

Depending on what your terminal is, it may be possible to capture the contents of the scroll-back buffer. rxvt-unicode can be induced to dump it to a temporary file with the escape sequence '\e[0i'. For tmux, you can use tmux -q capture-pane \; save-buffer -b 0 $TMPFILE \; delete-buffer -b 0. And screen can do screen -X hardcopy $TMPFILE. However, all these solutions will only work from a local zsh session. As soon as you use ssh or similar, the temporary files won't be on the same system as zsh.

These temporary files can be used for a custom completion widget. I have such a widget but it is a bit too long to paste in here.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .