46

On most mac applications Shift+Arrow selects text but in iterm it just moves the cursor without selecting. How do you get it to select the text?

Would also be curious if there's a way to do this in terminal.app, too.

truth1ness
  • 4,831
  • 5
  • 21
  • 19
  • Almost similar question, maybe it can clarify your point : http://superuser.com/questions/93573/select-text-in-iterm-using-keyboard – chesh May 05 '15 at 14:59
  • a terminal is not like "most applications"... the entire point of a terminal application is that whatever you type is sent into the program that is running in the terminal. A program would need to be designed to do something resembling the selection of text based off of the shift+arrow keypresses. As an example: when I run Vim inside iterm, it actually does just that (though it requires custom configuration to enable that behavior). But the concept of selecting a range of text in a bash terminal shell doesn't even exist. – Steven Lu Nov 29 '16 at 17:43

4 Answers4

38

Follow the directions in this superuser answer which describes using the iTerm custom key bindings to map + + to select by word. Its smart to make new key mappings in a profile to test it out, rather than the main keys preference.

Suggested keybindings

iTerm: Preferences > Profiles > Keys

Click + to add a keybinding, Click to Set

+ | Action: Move start of selection back > Move by character

+ | Action: Move end of selection forward > Move by character

+ + | Action: Move start of selection back > Move by word

+ + | Action: Move end of selection forward > Move by word


your ⌘ C or ⌘ V will work to copy/paste these selections

Merlin
  • 1,780
  • 1
  • 18
  • 20
27

in iterm it just moves the cursor without selecting. How do you get it to select >the text?

Yeah, iTerm has a special technique for text selection. Takes a little getting used to, but it's way faster than the ol' "shift+arrow" mac OS method.

If the text you want to select is anywhere in your current session's scrollback, just hit +f and then type the first few characters you want to select. iTerm will find the text and highlight it.

Then, hit tab to extend the selection to the end of the next word, repeating tab as many times as you need to fully select your required text.

When you're satisfied with the selection, go ahead and punch in your (+c) + (+V) or what have you.

Bonus: You can also use shift+tab to extend your selection backwards to the start of the previous word.

20

To extend @merlin answer here are some more iTerm2 key bindings for navigation/deletion

Del | send hex 0x15 | delete line

Del | send hex 0x1B 0x08 | delete word

| send hex 0x01 | move a cursor to the beginning of a line

| send hex 0x05 | move a cursor to the end of a line

| send esc seq Esc+b | move a cursor to the left by word

| send esc seq Esc+f | move a cursor to the right by word

| move start of sel back by word | select to the left by word

| move end of sel forward by word | select to the right by word

danylokos
  • 1,464
  • 15
  • 20
  • 1
    Shirt+Option+RightArrow/LeftArrow result in ;10C & ;10D being typed. How to make them performed as mentioned in this answer? I assume it's some setting in the preferences that I am unaware of. I will note that in my Profile "keys" settings I use "Natural Text Editing" – Lior Yehezkely Oct 08 '21 at 13:27
  • Here is mine [.itermkeymap](https://gist.github.com/danylokos/d2fe0b798b06b7132f935ac09044970c), but as far as I remember, I've not changed anything in settings except the key bindings. – danylokos Oct 12 '21 at 16:58
3

All these options are viable but there's something simpler one can do. In key mappings there's a special preset called "Natural text editing" that covers the most part. You would only need to add two shortcuts for text selection.

enter image description here

r4dixx
  • 61
  • 4