Sunday, january 24th, 2010

iTerm: word shortcuts

Warning: this entry is old. It may contain outdated information and may not reflect my opinion anymore.

In a terminal, I need both the “option” key to access alternate glyphs, like “•”, “∞” and French accents, like “é”, and to act like a “meta” key, which essentially sends an “escape” character followed by the key value.

Obviously a key can’t be two things at the same time, at least on Os X. On other Unix-like systems, you often have the left “alt” playing the role of the meta key, and the right “alt” playing the “altgr” role.

Some of the shortcuts I use the most are word navigation, using meta-left-arrow and meta-right-arrow, and word deletion, with meta-backspace (or “meta-delete” on Macs) to delete the word on the left, and meta-d to delete the word on the right.

So here are my recipies to bind those keys in iTerm.

What the heck does a “meta” key?

In most terminals, it simply sends the key you press while holding it, preceded with an “escape” character. So if you hit “esc”, then “delete”, it’ll delete the word on the left of the cursor. But deleting, or moving 10 words in a row is quite painful that way.

Holding the meta key, and hitting madly “delete” is much funnier!

The key mappings…

Essentially, you go to the “Bookmarks” menu, then select “Manage Profiles…”. In the window that pops up, open “Keyboard Profiles”, select “Global” (or whatever profile you normally use).

Then add a new key mapping by clicking on the “+” button.

Move one word right

Field Value
Key cursor right
Modifier Option
Action send escape sequence
Value f
High interception priority no

Move one word left

Field Value
Key cursor left
Modifier Option
Action send escape sequence
Value b
High interception priority no

Delete the word on the right

Also known as “forward-kill-word”. It’s generally present on two key bindings: alt-d and alt-del (“del” on a Mac is “delete” on other computers, the key above the arrows on a full keyboard).

option-d:

Field Value
Key hex code, “0x64” in the box
Modifier Option
Action send escape sequence
Value d
High interception priority yes

option-del:

Field Value
Key del
Modifier Option
Action send escape sequence
Value d
High interception priority no

Delete the word on the left

iTerm makes this a bit tricky because it doesn’t allow you to specify a character by its hexadecimal (or decimal, or octal) value. So you can’t send “\e\x7f” or such.

You could define it so it outputs a non-standard sequence, then map it in you .inputrc file (and in my case in the .inputrc file on many linux servers, and then in a bunch of applications that don’t use inputrc). But… there are other ways.

The first, and probably the less accessible way, is to apply a patch I posted earlier (see iTerm: extend the “send text” action) and compile iTerm yourself. But let’s not delve into this.

The second is to paste the 0x7f character, which is normally associated with the “backward delete” (named “delete” on Macs, and “backspace” on PCs).

Pasting a character who’s goal is to delete the character on the left may seem a bit daunting, but there are ways!

Field Value
Key delete
Modifier Option
Action send escape sequence
Value see below
High interception priority no

The “see below” value you have to enter is the pure character 0x7f. There are many ways to insert that invisible character.

Using the “Unicode Hex Input” keyboard

Go to the system preferences and add the “Unicode Hex Input” keyboard. In the text area, hold option and type 007f (while holding option). You won’t see anything, but it should be there.

Using the “Characters” palette

If you have the keyboard icon in the menu bar, select “Show Character Viewer”. In “View”, select “Code Tables”, then “Unicode”, then the line “Basic Latin”. In the character array below, on the “0070” line, the last character, in the “F” column, just right of the tilde (“~”)… it’s invisible. Select it by clicking one time on it. The background should turn blue.

Select the text input in iTerm’s key mapping window, then, in the Characters palette, click "insert".

Using UnicodeChecker

UnicodeChecker is a software similar to the Character Palette, but different…

In its window, scroll to “U+007F”. Then click in the huge blank box on the right, select all (command-a), copy (command-c), then paste it in iTerm’s text box.

Posted at 02:23
 
Tags: iTerm · osx · terminal

Comments

Comment RSS

Nice, this is the best way to configure backward-kill-word for iTerm I found. (Why can't it just work, like in Linux!?)

David – Tuesday, july 6th, 2010

Thank you very much! Living without this is possible, but not healthy. I tried a patch for it, but it made my tilde inaccessible (Swedish keyboard layout). This seems to work perfectly!

Patch: https://swissarmyhammer.wordpress.com/2010/06/07/osx-terminal-meta-key-national-characters/

jooize – Tuesday, august 24th, 2010

I was fooling around with my shortcuts in the OS X keyboard prefs and I think I overwrote the 'command+period' shortcut for iTerm. In Terminal.app this sends a SIG_HUP just as though you did ^C. I want to return this shortcut to iTerm, but if I setup an entry in my profile for this it doesn't register. I think this is because 'command+period' is reserved by OS X, but since there is no menu bar item for this function in iTerm, I cannot recreate this in the OS X keyboard prefs. I'm at a loss as to how to return this functionality as I much prefer command+period than control+c for killing interactive commands and such. Any help or even if you know an irc channel where you think someone might know more about this would be awesome.

Zach – Friday, october 1st, 2010

Actually Ctrl-C causes a SIGQUIT, not a SIGHUP.

You could patch iTerm to add a menu shortcut, or to add the possibility to map “.” in the existing shortcut system.

Or maybe an AppleScript script to send a 003 to the active iTerm window. I think there’s a way to bind scripts to keyboard shortcuts.

I haven’t tried any of them, but there seems to be a number of applications that might solve your problem too, like Cockpit, Spark, QuickKeys X, Keyboard Maestro, … (pick one of them on macupdate.com, and look at the comments, ratings, and similar apps).

Serge – Saturday, october 2nd, 2010

Thank you, Serge. Now I can jump through words in iTerm!

Andrey – Monday, october 25th, 2010

Drop a comment

Comments are closed for this entry.