2

I have a machine for which when I run fc it opens in the nano editor. How can I switch the editor to vim when I edit a command with fc?

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
leeand00
  • 4,443
  • 10
  • 51
  • 78

3 Answers3

4

If your shell follow the POSIX standard, the fc command will use the variable FCEDIT as the editor.

Setting FCEDIT in your shell's initialisation files will make the built-in fc command use the indicated editor in any new shell sessions:

FCEDIT=vim

You may also specify an editor with fc -e vim.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936
  • There is no need to export this. It is used by the shell internally only. – schily Jun 08 '18 at 08:58
  • @schily Unless `fc` is an external command. – Kusalananda Jun 08 '18 at 08:59
  • `fc` cannot be an external command as it works on internal data structures of the shell. It is a hack to do some primitive history editing using an external editor instead of implementing a real history editor in the shell. BTW: I implemented a prototype of an integrated history editor in 1982 and the first shell with fully integrated history editing under cursor control in 1984. The Korn Shell introduced `fc` in 1983 and a real history editor in 1986. Using `fc` today looks like an anachronism. I am used to have an integrated history editor in the shell since 34 years... – schily Jun 08 '18 at 09:05
  • @schily When pondering how I would implement `fc` as an external command, I realise that you may well be correct. I use `fc` daily, but mostly through `alias r='fc -s'`, and only rarely to actually edit old commands. – Kusalananda Jun 08 '18 at 09:10
  • The shell I used in 1984 is called `bsh` and has been written at H.Berthold AG. It is not a Bourne like shell but rather similar to `csh` but still closer to `sh` than csh. I never had the need for something like `fc` and I only implemented it in the Bourne Shell (`bosh`) , see http://schilytools.sourceforge.net/bosh.html because the author of the POSIX test suite claims that XSI support is needed for compliance unless you like to write only a shell for an embedded system. `dash` identifies as such a shell. It has no editor and no multi byte support. – schily Jun 08 '18 at 09:29
2

Just add to your /etc/profile following line, then log out and in again to make changes take affect.

export EDITOR=vim
Winnie Tigger
  • 447
  • 2
  • 7
2

On Debian and Ubuntu:

sudo update-alternatives --config editor
q0rban
  • 103
  • 3
max
  • 21
  • 1