Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTerm2: delete line?

I'm trying to map ⌘+Delete (backspace) to delete to the beginning of the line (like it works in browsers and text editors) in iTerm2 and I'm unable to find a working escape code for it. I tried 1K (^[1K) based on what I read in Wikipedia. It just prints a "K".

Edit: I found Ctrl+U. Now to find out how to map it. Maybe Hex code 21 (U being 21st letter), so 0x15?

like image 273
Steven Lu Avatar asked Mar 31 '13 19:03

Steven Lu


People also ask

How do you delete a line in Terminal Mac?

By the way, if you want to kill text from the cursor to the end of the line, you can press Ctrl - k . So instead of doing the binding described above, you can kill a whole line by pressing Ctrl - u Ctrl - k .

How do you select and delete iTerm2?

In OSX, ⌥+⌫ and ⌘+⌫ are the shortcuts for deleting a word and deleting a line respectively. ⌘+ ← and ⌘+ → are for going to the beginning and end of lines.

How do I quickly delete in terminal?

The rm command is used to delete one or more files located in the current directory – this operation is permanent. For that reason, you may need to use rm with the -i flag so that you can be prompted for confirmation.


1 Answers

I got it. I have no idea why Hex Code mappings in iTerm2 produce the associated Ctrl+key mappings, but they do. No idea what 0x00 means, either, as it's not assigned to A as might be expected. (though I do believe Unix has its own conventions relating to treating null bytes -- we have e.g. xargs accepting a null byte delimiting format from find for example -- It would be neat if we can bind this to a hotkey with iTerm2)

I was able to find that Ctrl+U does nearly the exact task I want (it deletes the entire line rather than deleting only what is before cursor, but whatever... Ctrl+Y as a bonus can bring it all back). Then I curiously saw that I had hex codes 0x1 and 0x5 mapped to ^A and ^E respectively, for my Cmd+Left and Cmd+Right... so 0x15 is for ^U!

like image 86
Steven Lu Avatar answered Sep 28 '22 17:09

Steven Lu