Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to use vi (set -o vi can do the trick) as default in my shell instead of emacs, but I do not want to put it into bash startup scripts.

Why? Because I work as verification engineer and I am using several user accounts, which are also quite often reinstalled. Changing of default profile is not answer too, because some of software creates its own home directory (independent on default profile).

EDIT: I know you gave me several ways how to do it at startup or anytime, but I do want to change it somewhere in system and have it as default, is this possible?

share|improve this question
What program do you use to login to these terminals? – SLY Jan 3 '11 at 20:36
Putty/unix ssh, but only 1st session, than I'm usually working in screen, but I'd like to have it portable .. independent on client side. – Ency Jan 3 '11 at 21:05
What do you envision doing this other than typing set -o vi yourself at your first prompt? – Dennis Williamson Jan 3 '11 at 21:18
Then if I start screen, su or something like that emacs is back. That's why. – Ency Jan 3 '11 at 21:22
Why don't/can't you just script the generation of these user accounts to include the bash profile you expect? – jgoldschrafe Jan 3 '11 at 21:41

This is actually fairly intuitive when you think about it, although it is not as obvious as it might seem at first. The following command will give you what you want:

ssh -t somehost "bash -i -o vi"

This will launch an interactive shell in vi mode. Lets break it down. ssh -t somehost connects to the host (obviously) and opens up a tty session. "bash -i -o vi" does two things. First, it launches bash in interactive mode, i.e., the shell you typically would receive when you login. This reads in the bash profiles, etc., and brings you to a prompt. The second argument, -o vi, enables shell options, specifically, vi mode.

To use this in a realistic environment, you'll probably want to do something like the following (adapting the path to bash or your shell of choice):

function ssh_vi { ssh -t $1 "bash -i -o vi" }

And called as...

$ ssh_vi

Hope this helps!

share|improve this answer
I think this solution, combined with something equivalent for when screen is started, is probably the right answer. Otherwise, look into autohotkey or equivalent. – Jed Daniels Jan 4 '11 at 5:44

It sounds like you want Putty to run a script for you. Have a look at ExtraPutty. or Kitty's auto-command.

share|improve this answer
up vote 0 down vote accepted

It seems to be impossible to do it only by configuration changes.
One possible solution seems to be change and recompile "readline" library.

share|improve this answer

Maybe, I just did not understand the problem, but to me it does not seem to be a problem at all: typical GNU systems do have a global /etc/inputrc config, doesn’t your? vi mode for readline(3) can be enabled by adding:

set editing-mode vi

to it, of course.

share|improve this answer

bash$ export EDITOR=vi all software that looks for this variable will use vi you can write as is into .bashrc so every time you start screen will use it

share|improve this answer
export EDITOR=vi does not work as set -o vi – Ency Jan 3 '11 at 21:26
you need to have the readline mode set to vi ? or you need vi as default editor ? – silviud Jan 3 '11 at 23:24
Well, yes I need vi readline mode as default – Ency Jan 4 '11 at 9:59

The answer is:

  1. Edit .*rc shell file (.bashrc .kshrc)

  2. Add line
    set -o vi

  3. Source shell profile file (.bash_profile / .profile) source ./.bash_profile

  4. Check
    set -o|egrep -w "(vi|emacs)"

share|improve this answer
The OP said he didn't want to put this definition in his bash startup scripts. – Katherine Villyard Feb 6 '15 at 21:52

Your Answer


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.