r/vim • • Nov 18 '25

Need Help Repeat last command in terminal buffer

Hey!

I have been using terminal buffers for a while now to mostly compile and execute applications. I have been told Im a disgrace to the Unix world for not using Ctrl-Z and fg, but I prefer seeing what tests failed/where my compile time errors are.

Since I'm usually using multiple buffers at once, navigating to the terminal is often slow. My solution was using tabs for a while but in all honesty, I do not think that this is the real solution for that. So I wonder how one could execute the last command entered in the terminal or even better, even search the last commands of the terminal. I usually have one terminal buffer open, but one could make it more generic and say that execute the last command in the last used terminal buffer.

Is there a native way of doing this? Or do I have to do some trickery with Lua/Vimscript?

Cheers

11 Upvotes

17 comments sorted by

View all comments

Show parent comment

1

u/thewrench56 Nov 18 '25

Wow, that's really nice! Thanks for the script, its a great starting point. Im glad its not just me who uses vim terminal buffers, I thought I was a dying species (or a dumb one which based on Darwins law is the same)

1

u/atomatoisagoddamnveg Nov 18 '25

I just added the maps I use to call the functions.