0

I've got the following in my vim config:

map <leader>ot :call OT()<cr>

function! OT()
    let fname = input("ot: ", "", "file")
    let res = system("ot --editor vim --print " . shellescape(fname))
    if v:shell_error
        echo "\n" . res
    else
        execute "e " res
    endif
endfunction

<leader>ot allows me to provide some data, like Module::Name, which then gets translated into an actual file name via Open::This and opened via the execute line. What I'd like to be able to do is to have an entry appear in my history (via histadd()?) which would allow me to re-run the function with the arguments I had originally supplied.

I've tried various incantations of histadd but I haven't been able to get there. Any tips would be appreciated.

1 Answer 1

1

Let's change the OT function to take an argument so that it is not "stateful" (i.e., a single history entry can correctly capture all the needed information):

nnoremap <leader>ot :call OT(input("ot: ", "", "file"))<cr>

function! OT(fname)
    let res = system("ot --editor vim --print " . shellescape(a:fname))
    if v:shell_error
        echo "\n" . res
    else
        execute "e " res
    endif
    call histadd(':', printf('call OT("%s")', escape(a:fname, '"\')))
endfunction

Then we can add the histadd, but we need to manipulate the string a bit to get it just right.


Alternately, just :call histadd('@', fname), then run your mapping and press Control+p.


N.B. I used nnoremap instead of map.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.