Executing the fc builtin causes bash and other shells to fire up $FCEDIT on the last command.

Because FCEDIT is a variable, this is inherently customizable.

Is it possible to also customize the editor that starts up when I press v in the command mode of set -o vi mode?


It turns out, the latter command follows whatever is set in $EDITOR, e.g., doing:

editor(){ vim +'set ft=sh' "$@"; }

Will cause vim, defaulting to sh syntax, to open for both v presses in command mode and for fc.

Edit: Thanks to alexander-batischev for pointing out that

editor(){ vim +'set ft=sh' "$@"; }

is sufficient.

( Interestingly,

EDITOR="vim +'set ft=sh'"

works for v, but not for fc, hence the editor function workaround.


| improve this answer | |
  • I didn't expect to figure it out by myself so quick, but maybe someone will find this useful (not sure if to keep it here now). – PSkocik Jun 19 '16 at 13:06
  • 1
    Actually, EDITOR is used by fc as a fallback if FCEDIT is not set, so you can get away with setting only EDITOR. – Alexander Batischev Jun 19 '16 at 13:08
  • It is useful. It shows how to tell vim that the file type is sh and thus gives a possibility of getting the right syntax highlighting etc. even though vim can't see a file name with a .sh suffix. That would not been possible without the use of that shell function I think. Maybe you could expand on the answer a bit? – Kusalananda Jun 19 '16 at 13:14
  • @AlexanderBatischev But setting EDITOR and leaving FCEDIT unset may have the side effect that other programs who invoke EDITOR may not do the right thing... – Kusalananda Jun 19 '16 at 13:21
  • @Kusalananda You're right, but there's no going around setting EDITOR. My suggestion only helps make the solution a bit shorter, that's all. – Alexander Batischev Jun 19 '16 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.