Shell vim defaulting to Insert or Command mode

On a daily basis I need to SSH into several different RHEL servers using Putty.

On some of the servers, if I up arrow to get a previous command, it automatically starts in Input Mode, so if I press up arrow, then 'x' it will type the letter x at the end of the command line. On other servers, it automatically starts in Command Mode, so if press up arrow, then 'x' it deletes the first character of the command.

I'm trying to understand how this default behavior is controlled. I've looked through the .bashrc, .bash_profile, .vimrc files and don't think I see where this is being set.

I prefer the second way since I spent many years working on AIX and that's the way it worked, but the biggest thing is I'd like is to make it consistent.

It seems like there must be a simple answer, but I must be using the wrong search terms trying to find it. Thanks in advance.

The vim (and vi ) utility always starts in command mode. One might guess that the default terminal setting (i.e. TERM=terminal_type ) differs on some of your servers and the escape sequence being generated for the up-arrow key on your terminal is being interpreted differently as a result. My guess would be that the escape sequence for that key includes an "a" or "i" or other vim command that puts you in insert mode when TERM is set to something like "dumb" or to a terminal type that does not match whatever terminal type Putty is emulating.

1 Like

For the behavior on the command line, see the discussion of vi-mode versus emacs-mode

1 Like

Thank you, that seems to be it. Specifically

set -o vi

makes it work the way I want it to. I appreciate the info!

You can set that in ~/.profile, if you're using ksh (i.e. not ~/.bashrc or ~/.bash_profile (~=your home directory))

And, obviously, if you prefer using Vi to "emacs" when your shell is Bash, you can set it in your Bash profile also :slight_smile:

1 Like