Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

This question has been asked in various forms and there are a few blog posts around the net but I can't seem to find one that works consistently. I'm going to ask it for my (and perhaps other's) sanity sake :)

I am trying to replicate the arrow movement actions that you see in mvim within iTerm2. The primary ones are listed below. there could be more that I will undoubtedly forget.


Left / Right

+ ← (command/cmd + arrow left) - move to the beginning of the line

+ → (command/cmd + arrow right) - move to the end of the line

+ ← (shift + arrow left) - move to the beginning of the word

+ → (shift + arrow right) - move to the beginning of the word

Up / Down

+ ↑ (command/cmd + arrow up) - move to the beginning of the file

+ ↓ (command/cmd + arrow down) - move to the end of the file

+ ↑ (shift + arrow up) - move to up 20% (i think??)

+ ↓ (shift + arrow down) - move down 20% (something like that?)


If you know of more, please let me know and I'll add them to the question.

Thanks!

share|improve this question

1 Answer 1

I would not try tp bind the cmd key outside any GUI application - But it can be done with iTerm2.

Let's get to the easier things first- You should proabably create some kind of testing environment:

  • Open up the iTerm2 configuration
  • Navigate to Profiles.
  • Select your current profile
  • Click Other Actions and then Duplicate Profile.

Actiate your new Profile, navigate to the Keys section and remove all references to Shift and your arrow key. If you launch a new Shell with this profile the Shift-Arrow combination should already work.

I've set my $TERM to xterm and there are a lot of other things which could influence the key mapping, but I've tried this and it worked:

  • Add a new entry within the tab Keys
  • Press your cmd-Arrow combination
  • As Action you must select Send Escape Sequences
  • Add the correct sequence
CMD-Up:    [1;5H 
CMD-Down:  [1;5F 
CMD-Left:  [1~
CMD:Right: [4~

iTerm2 will automatically prepend the Escape key ^[, so your config should look like this: Screenshot of the Keys tab

share|improve this answer
1  
I apologize, for whatever reason this didn't show up in my stack alerts. This worked, but it only seems to work in vim. It doesn't work in the normal command mode or rails console. Any ideas? –  Chance Apr 1 '12 at 16:42
    
Thanks by the way :) –  Chance Apr 1 '12 at 16:43
2  
I set my $TERM to xterm (from xterm-new) and still couldn't get it to cooperate. SHIFT+up prints A, down B, right C, left D. cmd + left/right move 1 character, cmd + up/down alert with no result –  Chance Apr 1 '12 at 16:47
    
Same as Chance here. –  mitjak May 24 '12 at 18:47
    
Did you map the escape sequences to the correct action? For example in zsh: bindkey bindkey '^[[1~' backward-word –  Sebastian Stumpf May 26 '12 at 17:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.