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

by on November 3, 2008 · 9 comments· LAST UPDATED November 25, 2012

in , ,

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.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 9 comments… read them below or add one }

1 Balint David May 18, 2009 at 9:30 am

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

Reply

2 Matt October 2, 2009 at 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
default/*
Open=%var{EDITOR:vim} %f
View=

And then?
Nothing…

Reply

3 Konstantin October 28, 2009 at 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 ;-)).

Reply

4 Azrael November 13, 2009 at 12:46 pm

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

Reply

5 Matt February 12, 2010 at 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!

Reply

6 robert May 29, 2010 at 8:24 am

worked for me. Thanks. Used nano though

Reply

7 Matt June 1, 2010 at 9:59 am

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

Reply

8 anonymous November 24, 2010 at 8:30 am

Thanks!

Reply

9 MLivshutz July 12, 2011 at 9:10 pm

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

Reply

Leave a Comment

Tagged as: , , , , , , , , ,

Previous post:

Next post: