How to stop a command in the Visual Studio Code terminal

Viewed 154531

I've been stopping commands with the trash can for too long. Command period doesn't work on Mac. I can't find anywhere how to stop the terminal via a command. What is it?

12 Answers

Ctrl + C works in the terminal, but it didn't work for me in Visual Studio Code. However, hitting Q did (when running a git diff for example).

In certain cases, such as running a Node.js server, Ctrl + C wouldn't work. Instead, you can stop the app or command by pressing Ctrl + Alt + M (i.e., Ctrl + Option + M for Mac users).

Sample JavaScript code to demonstrate this:

const http = require('http');

http.createServer((req, res) => {
    res.write('Hello, World!!');
    res.end();
}).listen(5000, () => console.log('Server running...'));

Many Mac users (including me) get confused with the Cmd and Ctrl keys. But Ctrl + C should work fine.

If you are on Linux, open the shortcuts:

Enter image description here

Then type kill, and this option will appear.

Double-click on the record, choose a shortcut for it, open the terminal, Ctrl + J, and press the shortcut you chose.

Enter image description here

The difference in pressing Ctrl + J and then Ctrl + J again to close, is that it will not keep the terminal process, but only close it.

Hitting Esc clears out the terminal and cancels everything.

Neither Ctrl + C nor the trash icon actually stopped the server for me.

If you are using the Live Server extension by Ritwick Day, there should be a label on the bar at the bottom for the status of the server.

If it reads Port: 5500 it means it's running. Just click on it to stop it.

Stop live server

The same label now should say Go Live. Click on it in order to do exactly that.

Start live server

You can stop any running command by pressing Ctrl + C on your keyboard.

If it is ':' you see, then Q + Enter.

For example: git config --list (this will take you to the colon(':') and you may not be able to escape this)

In Visual Studio Code, first hit Ctrl + C.

It will ask the following question;

Terminate batch job (Y/N)?

Press Y + Enter.

After this, run the following command on the prompt:

exit + <Enter>

It will stop the instance.

You can kind of bypass the issue by writing system("pause") at the very end of your main function. That works for me like a charm...

In Visual Studio (2022) the shortcut may actually Ctrl+Pause/Break instead of Ctrl+C.

Related