27

The question is quite straightforward, so no further description is needed according to me.

I just add that I am running Ubuntu 13.04.

Any help is welcomed.

manatwork
  • 31,277
Jendas
  • 405

3 Answers3

35

Run MC as usual. On the command line right above the bottom row of menu selections type

select-editor

This should open a menu with a list of all of your installed editors. This is working for me on all my current Linux machines.

24

In Midnight Commander go to Options menu / Configuration... command / Use internal edit checkbox and uncheck it. (Don't forget to execute the Save setup command if the Auto save setup option is off.)

Then set the EDITOR environment variable to Sublime. You may prefer to add one of these to your shell's resource file:

  • Global setting for all programs that use EDITOR (not recommended):

    EDITOR=sublime
    export EDITOR
    
  • Temporary setting for the given Midnight Commander session only:

    alias mc='EDITOR=sublime mc'
    

Same for the viewer, just you uncheck the Use internal view option and set the VIEWER environment variable instead.

manatwork
  • 31,277
  • why is it not recommended to set EDITOR=sublime globally? – MattDMo Jun 27 '13 at 16:07
  • 3
    Because other tools, for example crontab, are using it. Such tools may be used without X (for example from a virtual terminal in single user mode for maintenance operations) or by user who has no running X instance (for example through su -). So better keep EDITOR set to a text mode editor. – manatwork Jun 27 '13 at 16:12
  • Why 'EDITOR='sublime -w' does not work? (It seems MC ignore any supplyed options) – Eugen Konkov Sep 14 '15 at 09:31
-1

Although this topic is old, Midnight Commander keeps using vi as default in my Tumbleweed.

I checked the setup on my Raspberry (that is Debian based Buster). At first run mc offers there "select editor", that is creating a writable file in $HOME/.selected_editor. You can create it with

touch $HOME/.selected_editor

It further has a symlink

/etc/alternatives/@editor pointing to /usr/bin/nano

Create that symlink and save the three further executable script files in /usr/bin:

sensible-pager

#!/bin/sh

Prevent recursive loops, where these values are set to this script

p="$(which sensible-pager)" [ "$(which $PAGER || true)" = "$p" ] && PAGER=

${PAGER:-pager} "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then more "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then echo "Couldn't find a pager!" 1>&2 echo "Set the $PAGER environment variable to your desired pager." 1>&2 exit 1 fi fi

sensible-editor

#!/bin/sh

ret="$?"

Prevent recursive loops, where these values are set to this script

p="$(which sensible-editor)" [ "$(which $EDITOR || true)" = "$p" ] && EDITOR= [ "$(which $VISUAL || true)" = "$p" ] && VISUAL= [ "$(which $SELECTED_EDITOR || true)" = "$p" ] && SELECTED_EDITOR=

if [ -n "$VISUAL" ]; then ${VISUAL} "$@" ret="$?" if [ "$ret" -ne 126 ] && [ "$ret" -ne 127 ]; then exit "$ret" fi fi

if [ -r ~/.selected_editor ]; then . ~/.selected_editor 2>/dev/null || true elif [ -z "$EDITOR" ] && [ -z "$SELECTED_EDITOR" ] && [ -t 0 ]; then select-editor && . ~/.selected_editor 2>/dev/null || true fi ${EDITOR:-${SELECTED_EDITOR:-editor}} "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then nano "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then nano-tiny "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then vi "$@" ret="$?" if [ "$ret" -eq 126 ] || [ "$ret" -eq 127 ]; then echo "Couldn't find an editor!" 1>&2 echo "Set the $EDITOR environment variable to your desired editor." 1>&2 exit 1 fi fi fi fi exit "$ret"

sensible-browser

#!/bin/sh

Prevent recursive loops, where these values are set to this script

p="$(which sensible-browser)" [ "$(which $BROWSER || true)" = "$p" ] && BROWSER=

if test -n "$BROWSER"; then ${BROWSER} "$@" ret="$?" if [ "$ret" -ne 126 ] && [ "$ret" -ne 127 ]; then exit "$ret" fi fi

if test -n "$DISPLAY"; then if test -n "$GNOME_DESKTOP_SESSION_ID"; then if test -x /usr/bin/gnome-www-browser; then exec /usr/bin/gnome-www-browser "$@" elif test -x /usr/bin/x-www-browser; then exec /usr/bin/x-www-browser "$@" elif test -x /usr/bin/gnome-terminal && test -x /usr/bin/www-browser; then exec /usr/bin/gnome-terminal -x /usr/bin/www-browser "$@" fi fi if test -x /usr/bin/x-www-browser; then exec /usr/bin/x-www-browser "$@" elif test -x /usr/bin/x-terminal-emulator && test -x /usr/bin/www-browser; then exec /usr/bin/x-terminal-emulator -x /usr/bin/www-browser "$@" fi elif test -x /usr/bin/www-browser; then exec /usr/bin/www-browser "$@" fi

printf "Couldn't find a suitable web browser!\n" >&2 printf "Set the BROWSER environment variable to your desired browser.\n" >&2 exit 1;

I was really surprised but after these steps nano is the editor when using F4.

AdminBee
  • 22,803