30

Run across this constantly since I'm a web developer, 'cmd-r' has the side effect of preventing the arrow keys from working in any mode, but I can't imagine that's the purpose and I haven't been able to find any documentation as to what it's actually supposed to do.

Edit: Apparently this is actually a mac terminal command, 'Send Reset', so I guess this now a question of "What purpose does the send reset command serve?" Explains why I wasn't able to find it in the vim docs though.

0

4 Answers 4

29

To avoid this annoyance, I remap Command-R to "Ignore" in the iTerm key mapping.

enter image description here

1
  • 1
    Thank you. This was getting terribly annoying. Commented Mar 5, 2020 at 15:54
14

This happens to me even when not using screen and I've found I can return to normality by clearing the terminal running vim (I've also tested this with tmux but not screen:

:!clear
1
  • 2
    An alternative: ^Z followed by fg. Commented Feb 22, 2022 at 4:06
7

This question has been answered here: when running screen on OSX, command+r messes up arrow keys in vim across all screens

Copied answer:

As a good little Vim advocate, I feel bound to tell you to learn to use hjkl as your cursor keys. Halfway through exploring the problem, I thought it had mysteriously fixed itself, until I realized I was testing using hjkl instead of the actual arrow keys.

Anyway, now for a real answer.

Instead of shutting down all your screens and restarting, you can take advantage of screen's ability to move between terminals. Hit CTRL+A CTRL+D to detach screen from your terminal, then run screen -D -R to reattach. This should make your arrow keys work again.

If you're not in screen, but just in Vim, then you can CTRL+Z and type fg for the same effect.

You could also work around the cursor key problem in Vim, but the reset might have changed other terminal options, so it's safer to do as described above lest you see other random display/keyboard problems. If you want the remappings anyway, here they are:

map <Esc>[A <Up>
map <Esc>[B <Down>
map <Esc>[C <Right>
map <Esc>[D <Left>

Grubby details:

Both Vim and screen use the ncurses library to manage the terminal. One of the things ncurses is doing when it takes control of a VT100-compatible terminal is switching the arrow keys into "application mode", which changes the codes they emit. The up-arrow key, for example, changes from Esc [ A to Esc O A. The VT100 control code it emits to do this is Esc [ ? 1 h. The terminal reset command sent by Command+R resets the cursor keys to the default.

Detaching and reattaching screen causes ncurses to retake control of the terminal, which reapplies all of the settings it likes, so that's probably the most portable and reliable way to restore things to normal.

VT100 control codes: http://www.handshake.de/infobase/dfue/prgrmmer/t322.htm

1
  • Yeah, found that after I posted, saw "The terminal reset command sent by Command+R resets the cursor keys to the default.", would still be great to know exactly why that happens. I'm honestly mostly interesting in knowing what the intended use of this command is though, which that doesn't answer.
    – GlyphGryph
    Commented Aug 19, 2014 at 17:02
0

Thanks @Benjamin Carlsson for this solution in the comment above!

Using Ctrl + z followed by fd + enter did the trick

You must log in to answer this question.

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