16

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.

  • I had a look at the source code and yes the feature was around in 0.7.0 of iTerm (not iTerm2). But is commented out (in file PTYSession.m) in the trunk (and probably earlier versions too). And it iTerm2 the function is still there but empty and therefore doesn't do anything. – boretom Mar 10 '12 at 23:46
6
+50

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).

  • wow, great stuff! pre-compiled binary seems to work fine on my end so far but will keep an eye on it. thanks a million! – Jeff Mar 11 '12 at 22:58
  • 404 not found... – aeroxy Nov 13 '17 at 7:47
  • 1
    Hey @aeroxy, that change was merged long ago into upstream iTerm (github.com/gnachman/iTerm2/pull/77). Some time ago I removed my fork since that was the only it existed. – boretom Nov 14 '17 at 20:58
  • @boretom then it seems mine iterm2 3.1.5.beta.1 still has similar issue. It seems like when I do Options-Click it just goes to last command (arrow up). apple.stackexchange.com/questions/305554/… – aeroxy Nov 15 '17 at 2:05
  • @aeroxy, if works excellent with 3.1.5.beta2 on my macOS 10.12.6 with "Opt-Click moves cursor" checked in Preferences > Pointer. It's all about positioning the cursor on the current line. Is that what you try to achieve? – boretom Nov 15 '17 at 22:36
2

iTerm 2 is not a new version of iTerm - while based on the same source code, there are major changes under the hood. One of the things that was removed or broken (hard to speak to the developer's intent) was cursor positioning.

You're not the only one who noticed this omission; it's been filed as a bug since April 2011 and continues to attract attention. Your best option for getting this feature (besides forking it on GitHub or switching to another application) is to submit a comment at the Google Code site above. Hopefully with enough interest, this feature will make it back into the product.

2

The latest builds now include this feature, as of March 15 2012.

Official Download site: http://code.google.com/p/iterm2/downloads/list

The latest build (Currently March 26th 2012) includes this feature.

2

This is no longer working in the latest build, you'll have to go back to https://code.google.com/p/iterm2/downloads/detail?name=iTerm2-1_0_0_20120726.zip

as mentioned in the original ticket that got the feature added: https://code.google.com/p/iterm2/issues/detail?id=789

1

The latest version of iterm2 (I'm using Build 2.9.20150812-nightly) has this feature, but in order for it to work with multiple lines you have to enable shell integration as described at https://gitlab.com/gnachman/iterm2/issues/3638.

To install the latest iTerm, I use brew and execute the following:

brew tap caskroom/versions && brew cask install iterm2-nightly

1

My answer is tested in 2019 with iTerm2.

Go to Settings > Profiles, select the desired profile (can be the Default one, you'll have to repeat this for each one), select the "Keys" tab, and change the behavior of the LEFT and RIGHT Option (alt) keys to Esc +

enter image description here

This is actually in their FAQ:

Q: How do I make the option/alt key act like Meta or send escape codes? A: Go to Preferences > Profiles tab. Select your profile on the left, and then open the Keyboard tab. At the bottom is a set of buttons that lets you select the behavior of the Option key. For most users, Esc+ will be the best choice.

BONUS

If you are asking about Option (Alt) + click, I assume you also want your Option (Alt) + Backspace to work.

In the same UI (Keys panel), click the button "Load Preset" and choose "Natural Text Editing". Repeat that for each one of your presets.

Now you'll have both Option + click and Option + backspace working.

You must log in to answer this question.

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