terminal – Exploring Option + Click Functions in iTerm

itermkeyboardterminal

In Terminal, Option + click allows me to place my cursor at any point on the current line– great for editing really long commands.

How can I do this in iTerm2?

Update: According to this page, the feature has been around since 0.7.0 (2003). I've also noticed that if I hold Command+Option, the cursor changes into the familiar cross like in Terminal… but clicking still does not reposition my cursor.

Best Answer

I was wondering "How Hard Can It Be(c)" to implement it and gave it a go today.

The Terminal.app seems to emulate 'move cursor to left/right' ESC sequences. You'll hear the famous 'beep' if you try to place the cursor in the shell prompt. And you'll hear it as many times as there are invalid moves.

The solution in iTerm2 works the same by invoking the appropriate ESC sequences. Although it beeps only once if you try to place the cursor in an invalid area ;)

Terminal.app seems not to be able to handle multi-line prompts, only moving on the last line seems to work. Multi-line prompts in this implementation should be handled correct.

Results can be found on github. It's a fork of the original with a pending pull request. The branch I work on is named 'option-click-hardcoded'.

And of course it's highly untested. That means tested only by me on my late-2007 MacBook Pro running Mac OS X 10.7.3.

If you'd like try it out by compiling it yourself or download the precompiled binary for i386/x86_64/ppc iTerm_v1.0.0.git-085ec22c.zip).