visual studio code - Copy current input from integrated terminal to clipboard - Stack Overflow

admin2025-04-18  2

I often have multiple integrated (bash / zsh) terminals open in VS Code. Sometimes I enter a command in the wrong terminal (e.g. git commit ... in a terminal without pre-commit hooks in the environment).

Currently, I then press up to show the most recent command, manually select the input using the mouse, copy to clipboard, switch terminals, where I paste and re-run the command.

It'd be great to perform these steps without relying on the mouse. Hence, I am wondering whether there is a shortcut / keyboard binding to copy the input of the current integrated terminal to the system clipboard?

I often have multiple integrated (bash / zsh) terminals open in VS Code. Sometimes I enter a command in the wrong terminal (e.g. git commit ... in a terminal without pre-commit hooks in the environment).

Currently, I then press up to show the most recent command, manually select the input using the mouse, copy to clipboard, switch terminals, where I paste and re-run the command.

It'd be great to perform these steps without relying on the mouse. Hence, I am wondering whether there is a shortcut / keyboard binding to copy the input of the current integrated terminal to the system clipboard?

Share edited Jan 30 at 15:12 oguz ismail 51k16 gold badges60 silver badges79 bronze badges asked Jan 30 at 14:05 HericksHericks 10.9k2 gold badges25 silver badges35 bronze badges 7
  • What OS are you running? – grawity_u1686 Commented Jan 30 at 15:05
  • @grawity_u1686 I am running Sequoia 15.2 locally and usually connect to an EC2 instance running Amazon Linux 2. – Hericks Commented Jan 30 at 15:29
  • Why are people downvoting without any insight on how to improve the question? I'll happily edit the question if crucial information are missing. – Hericks Commented Jan 30 at 15:30
  • There is a Terminal: Copy Last Command command - but it doesn't do anything for me in Git Bash on Windows. – Mark Commented Jan 30 at 23:13
  • 1 @user1934428 It is a programming problem by definition, since it is about a tool commonly used for programming. – Mark Commented Jan 31 at 22:53
 |  Show 2 more comments

1 Answer 1

Reset to default 1

When you are in bash/VSCode/MacOS, you can define a key binding with :

bind "\"$(tput kf4)\":\"'|pbcopy\x01 echo '\n\""

then you can recall a command, type F4, the command text will be copied into clipboard.

This needs to be tuned if your command contains single quotes.

转载请注明原文地址:http://anycun.com/QandA/1744914561a89414.html