How To Use vi as Default Editor and Viewer in Midnight Commander

This is an user contributed article.

Midnight Commander (mc) is an user-friendly text-based file manager UI for Unix. Using mc, you can browse the filesystem easily and manipulate the files and directories quickly. You will not miss the standard command line prompt, which is also available within the mc itself. If you are new to mc, Midnight Commander (mc) Guide: Powerful Text based File Manager for Unix article will give you a quick jumpstart. In this article, let us review how to solve couple of common annoyance about viewing a file in mc.

Use vi as default editor and viewer in mc

Mc uses mcedit for file editor and mcview for file viewer. Like most of you, I’m very comfortable with vi and would like to use vi for both viewing and editing than the mc’s internal editor and viewer.

Launch mc in color mode by typing “mc -c” from the command line. Press F9 (or Esc followed by 9) to activate the top menu → select Options menu → select Configurations menu-item, which will display “Configure Options” dialog → de-select the check-box next to “Use Internal Edit” and “Use Internal View”, as shown below to disable, internal editor and viewer.

After this change, when you select a file and press Esc 3 to view or Esc 4 to edit, mc will use vi.

Fig.01 Mc configure options to disable internal editor and viewer

Fig.01 Mc configure options to disable internal editor and viewer

Change the Enter key behavior to view file using vi instead of executing it.

When you select a shell script and press enter, mc will execute it by default. Also, by default when you press enter on text files, nothing happens. I prefer to view the shell script when I press enter key. Also, I would like to view the text file using vi when I press enter key. You can achieve this by modifying the mc extension file as shown below.

Press F9 (or Esc followed by 9) to active the top menu. From command menu → select “Edit extension file” men-item → This will display the extension file. Go to the bottom of the extension file and change the value of open and view parameter values as shown below.

# Default target for anything not described above default/*

        Open=%var{EDITOR:vi} %f
        View=%var{EDITOR:vi} %f 

After the above change, when you press enter key on a shell script, it will open it in vi instead of executing it. This will also open text files in vi when you press enter after selecting it.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 10 comments so far... add one
CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
10 comments… add one
  • Balint David May 18, 2009 @ 9:30

    Cool! Thanks!
    I’m too dumb for vi, but it works with nano, too 😀

  • Matt Oct 2, 2009 @ 13:24

    Notwork – Network which does not work. And that’s what i mean 🙂
    (matt(pts/0)home ~)$ tail -6 ~/.mc/bindings |head -3
    Open=%var{EDITOR:vim} %f

    And then?

  • Konstantin Oct 28, 2009 @ 10:59

    Actually un-selecting the checkbox “Use Internal Edit” tells Midnight Commander to use the environment variable EDITOR which can be set to any text editor you like (even emacs ;-)).

  • Azrael Nov 13, 2009 @ 12:46

    As for the viewer, mc will use the one specified by the PAGER variable (“less” on my OS)

  • Matt Feb 12, 2010 @ 12:26

    True, Konstatin. Lol
    Anyway the ~/.mc/bindings file won’t work for me at all. I used the $EDITOR global in profile to set it up 🙂

    Thanks anyway!

  • robert May 29, 2010 @ 8:24

    worked for me. Thanks. Used nano though

  • Matt Jun 1, 2010 @ 9:59

    Ok, hacked a little and somehow forced VIM to work too. :]

  • anonymous Nov 24, 2010 @ 8:30


  • MLivshutz Jul 12, 2011 @ 21:10

    Works like a charm. It was set to nano by default and now it feels a lot better. Thanks Ramesh.

  • tony Oct 7, 2016 @ 21:12

    I turned off use of the internal editor, and it uses nano, even though vim is set as my default editor.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum