≡ Menu

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.

Share this on:

Your support makes a big difference:
I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft, takes a lot of my time and hard work to produce. If you use nixCraft, who likes it, helps me with donations:
Become a Supporter →    Make a contribution via Paypal/Bitcoin →   

Don't Miss Any Linux and Unix Tips

Get nixCraft in your inbox. It's free:

{ 10 comments… add one }
  • Balint David May 18, 2009, 9:30 am

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

  • Matt October 2, 2009, 1:24 pm

    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 October 28, 2009, 10:59 am

    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 November 13, 2009, 12:46 pm

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

  • Matt February 12, 2010, 12:26 pm

    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 am

    worked for me. Thanks. Used nano though

  • Matt June 1, 2010, 9:59 am

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

  • anonymous November 24, 2010, 8:30 am


  • MLivshutz July 12, 2011, 9:10 pm

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

  • tony October 7, 2016, 9:12 pm

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

Leave a Comment

   Tagged with: , , , , , , , , ,