1

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?

Yu Hao
  • 103
  • 4
Ency
  • 1,201
  • 1
  • 19
  • 26

6 Answers6

3

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 mysite.com

Hope this helps!

Andrew M.
  • 10,982
  • 2
  • 34
  • 29
  • 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 04 '11 at 05:44
1

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.

0

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

RedGrittyBrick
  • 3,792
  • 1
  • 16
  • 21
0

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

Ency
  • 1,201
  • 1
  • 19
  • 26
-2

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

silviud
  • 2,677
  • 2
  • 16
  • 19
-2

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)"

dragoStin
  • 1
  • 1