I'm looking for a way to select a block of text in Iterm2 and delete it.

Something like the following example, where I delete a selection of text in the middle of a line.

> python3 main.py bad arguments good arguments
> python3 main.py ■■■■■■■■■■■■■ good arguments
(click some key...)
> python3 main.py good arguments

I know there are shortcuts to "Delete line after cursor", but that would not work here since I don't want to delete the entire line after the cursor.

Is there any feature like this in Iterm2? It's exactly the same as an average text editor which lets you select and delete text within a line.

Note: I'm using zsh for my shell

  • Might you let us know which shell you use? there's not a general way to do this, so perhaps we can show you how to use the command history for your chosen shell to repeat and delete several words using key commands (emacs or vi style). If possible use the edit command to add details if no one gives a good answer
    – bmike
    Dec 31, 2022 at 17:04
  • I use the zsh shell, but if any other shell can give this functionality relatively easily, I'd switch to it Dec 31, 2022 at 18:27

2 Answers 2


This is not related to ITerm2; it has to do with your shell (Bash, Zsh, etc.) and/or editor. For all intents and purposes, iTerm2 is nothing more than a facilitator - the interface -to the CLI (shell) into your system; it’s not a text editor.

That said, Bash, for example, does have some rudimentary editing capabilities. For example, OptionD (Option = Meta or Alt) will allow you to delete from the cursor position to the end of a word.

If you’re using an editor like vi, it has its own commands to edit text. For example, D D deletes an entire line, D Space deletes to the next word, and D 5 deletes exactly 5 characters.

All of this is a function of the shell and/or editor, not iTerm2

What you need to remember is that while you can use your mouse to select and copy text; that text is not being held in memory like a document in TextEdit would. It’s being held in a scrollback buffer. Think of it as a running paper tape of everything on the screen. Yes, you can look at it and even copy selections, but you can’t edit it.


ESC D is kill-word and CTRL-W is kill-word-backward in zsh.

(assuming the shell is configured for emacs mode)

All documented in man zshzle.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .