I've recently just switched over to macOS from Windows and I previously used PowerShell. In PowerShell, I could type out a command and hit ctrl/command a
and it would select whatever I wrote, so that I could copy/delete it.
When I press command a
in the macOS terminal, it selects the whole window and doesn't let me copy/delete the line I was writing.
Anybody know how to just select what's written and copy/delete it?
Best Answer
Emacs-style shortcuts
To delete all you've written, you can press Ctrlu.
If you are at the start of the line, press Ctrlk.
To copy text, you can use the kill ring:
These are some of the Emacs keybindings that macOS implements for (most) text fields. There are plenty of those, and it's very useful to learn them, since with the additional Ctrl key, you have access to more navigational shortcuts.
Note that the copy-paste operation described above does not use the system clipboard. To select the entire line, you can triple-click it. But this will also include any prompt prefix (e.g.,
$
) that you might have configured.Alternative: iTerm2
I'd ditch Terminal.app and use iTerm2 instead. Apart from many other features that Terminal.app does not have, it offers Copy Mode (⇧CmdC), which allows you to use your keyboard to make selections.
For example, you can:
Now your native macOS clipboard will have the contents of what you just copied.