I know how to set the keyboard editing in bash to vi (set -o vi), and probably I could do it in bashrc. But I use bash in a variety accounts and contexts and want it to just default to vi over emacs no matter what.

Is there some way to force the default for the system (Ubuntu 23.04 in my case) to always be vi?

  • If you only want to make this configuration if you are using bash, then I would use [ -n "$BASH_VERSION" ] && set -o vi.
    – Cyrus
    May 29 at 22:13

1 Answer 1


You can set it in /etc/profile which should be read by all login shells including (depending on your setup, this varies) when logging in graphically. So add

set -o vi

to /etc/profile, and then add the same line to /etc/bash.bashrc and it should work in most cases.

  • On the other hand: The checking the VISUAL environment variable is a Z shell thing and /etc/profile does not apply to non-login interactive shells, so a perhaps better approach, where everywhere also covers (say) shelling out of vi, would be also setting up a ~/.bashrc for every account and priming that in /etc/skel or wherever. (-:
    – JdeBP
    May 29 at 18:21
  • @JdeBP yeah, I thought of skel, but that would only affect new accounts. Plus, the OP explicitly asked for a global setting. In most systems, at least in Linux, profile is read when you first log in and so this should be inherited by at least a majority of the shells you open.
    – terdon
    May 29 at 19:00
  • Applied to the login shell, yes; inherited and global, no. It isn't an environment variable. Try shelling out from (say) vi with :shell with your answer in place. Ironically, the Bourne Again shell is the only one (excluding actual Bourne and predecessors) that doesn't have something that interactive shells, either login or subordinate, always look at, for setting command-line editing configuration like this in one place.
    – JdeBP
    May 29 at 21:52
  • @JdeBP oh duh, of course it won't be inherited. Like an idiot, I tested by running bash --login where, of course, it worked. I don't have time to play with this right now, but I guess adding to both /etc/profile and /etc/bash.bashrc will be the best we can do.
    – terdon
    May 29 at 23:01
  • Done, @JdeBP, thanks.
    – terdon
    May 30 at 21:17

You must log in to answer this question.

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