Execute last command in last active terminal

0

My current setup to develop is a terminal to execute my code and multiple vim sessions in which I write my code.

Since I constantly work on smaller functions and compile/execute them frequently I often have to switch to the terminal just to run my code and see the current output.

Is there a way I to set a hotkey to execute the last command (compile and execute) in the terminal while staying with the cursor in the vim window?

I run Ubuntu and use the i3 windows manager.

Natjo

Posted 2017-02-16T22:59:45.043

Reputation: 335

May be I misread your question, but if you hit "Up" arrow on the keyboard when you are in terminal window, it will restore in command line previously executed command. You can hit it multiple times to see more commands from history – Alex – 2017-02-16T23:29:27.870

The problem is, that I have to switch to the terminal for this. I want to execute the terminal command while being in the vim window. I update my question – Natjo – 2017-02-16T23:35:49.863

Answers

1

You can use key mapping

:map <F9> @:

It will repeat last executed command.
Run your command with :! ProgramYouWantToRun > /dev/pts/X

Where right X is the terminal you want.
This X can be obtained by running tty command in the terminal where you want to execute your code.

When you press F9 it will repeat execution :! ProgramYouWantToRun > /dev/pts/X

P.S.

More on key mapping in vim you can find here

Alex

Posted 2017-02-16T22:59:45.043

Reputation: 5 606

This in combination with this kind of command: :! ProgramYouWantToRun > /dev/pts/X where X is the terminal you want. I find the right X by running tty in the terminal I want to execute my code. Maybe you update your answer with this additional information. – Natjo – 2017-02-17T11:09:47.460

1@Jonas Added. Thanks for additional information! – Alex – 2017-02-17T11:23:38.423