Macos – Unintentional vi mode in iTerm on Mac

command lineiterm2macosvim

I occasionally find that while working in iTerm the default Readline key bindings are replaced with the vi keybindings.

For example, I will try to go to the beginning of the line with ctrla, and instead it will print the character ^A, and then I won't be able to insert any text until I enter insert mode. I know this can be configured by setting the editing-mode in my inputrc file, but I don’t have that set in mine. Is there a way that I could be dynamically entering vi mode?

Best Answer

I believe this issue is related to the way the Mac OS X terminal handles terminal emulation and even color coding—which is related to control sequences—as explained in this blog post:

After upgrading to Lion I noticed that the Homebrew theme that I’ve been using since Snow Leopard doesn’t display colors correctly(using different colors for directories, different types of files etc.) any more when working on remote hosts via ssh (local dir colors still work though) and switching to other themes doesn’t help. After messing around with the Terminal settings I finally found the cause and a solution. It seems Lion changed the terminal type to xterm-color256 during the upgrade (don’t remember what the setting was in SL though). The solution is simple enough, just change the emulation type for terminal from xterm-color256 to xterm-color (see screenshot below).

Fair warning, some of the advice in that comment thread is out of date since there no longer is a xterm-color in the terminal as of Mac OS X 10.8 (Mountain Lion). But I believe adjusting items in the “Advanced” tab (pictured) might help:

enter image description here

Related Question