Midnight Commander: Difference between revisions
(moved from Linux Commands page) |
|||
(26 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
'''mc''' or '''Midnight Commander''' is a powerful file manager working in a shell terminal. |
'''mc''' or '''Midnight Commander''' is a powerful file manager working in a shell terminal. |
||
== ini file == |
|||
== Links == |
|||
* '''mc''' will only save the option ini file if there is a directory <tt>~/.mc</tt> in home directory: |
|||
* [http://polishlinux.org/apps/cli/midnight-commander-in-action/ Cool review of mc in action] |
|||
{{pl2|<source lang="bash" enclose="prevalid"> |
|||
* [http://www.nongnu.org/gcmd/ The GNOME Commander], a X alternative of <tt>mc</tt> under Gnome |
|||
mkdir ~/.mc |
|||
* [http://www.krusader.org/index.php Krusader], a X alternative of <tt>mc</tt> under KDE |
|||
</source>}} |
|||
;Color schemes |
|||
* [https://github.com/peel/mc Midnight Commander Solarized] |
|||
== VirtualFS == |
|||
* Shell filesystem: {{blue|<tt>/#sh:[user@]machine[:options]/[remote_dir]</tt>}} |
|||
== Configuration == |
|||
* To use '''vi''' as standard editor/viewer |
* To use '''vi''' as standard editor/viewer |
||
: First menu '''Options''' → '''Configuration...''' → '''uncheck''' ''use internal edIt'' and ''Use internal view''. |
: First menu '''Options''' → '''Configuration...''' → '''uncheck''' ''use internal edIt'' and ''Use internal view''. |
||
: Next, at the end of file <tt>.mc/bindings</tt>: |
: Next, at the end of file <tt>.mc/bindings</tt>: |
||
<source lang="text"> |
|||
default/* |
default/* |
||
Open= |
Open= |
||
View=view %f |
View=view %f |
||
Edit=%var{EDITOR:vi} %f |
Edit=%var{EDITOR:vi} %f |
||
</source> |
</source> |
||
* Edit <tt>/etc/mc/mc.keymap*</tt> to use {{kb|C-n}} for '''Auto-Complete''' (instead of {{kb|Alt-Tab}} that does not work in graphical environment) (see [[#Keyboard shortcuts|below]]) |
|||
== Keyboard shorcuts == |
|||
* Check '''complete: show all''' (so that selection box is shown on first ambiguity) |
|||
* '''Gnome-Terminal''' — To solve the conflicts with '''Gnome Terminal''', disable the ''Terminal menu shortcut key'' (to enable <tt>F10</tt>) and ''Menu Access Keys'' (to enable <tt>A-h</tt>...) in ''Gnome-Terminal''. |
|||
* To have common history between ''mc'' sub-shell and parent shell: [http://superuser.com/questions/845667/midnight-commander-subshell-sharing-a-history-file-with-the-shell-mc-was-start]: |
|||
* '''Auto-Complete''' — The usual shortcut for auto-complete '''Meta-Tab''' (i.e. '''Alt-Tab''') doesn't work in graphical environment because it is used for switching between windows. As a replacement, one can use '''Esc-Tab''', or can define a new shortcut with <tt>Options... → Learn Keys...</tt> (e.g. use '''Ctrl-N''' as in ''Vim''). |
|||
<source lang=bash> |
|||
* Frequently used keyboard shortcut |
|||
alias mc='PROMPT_COMMAND="history -a; history -r" mc; history -r' |
|||
</source> |
|||
* Add the following to {{file|~/.bash_profile}} and {{file|~/.profile}} to Meta-key ({{kb|Alt}}) not working and ''Midnight Commander'' displays <code>Press any key...</code> after each command when in ''tmux'' session [https://www.midnight-commander.org/ticket/2479]: |
|||
<source lang=bash> |
|||
# This fix meta-key support and stop mc displaying "Press any key..." in tmux session |
|||
if [ $TERM = "screen" ]; then |
|||
export TERM=xterm |
|||
fi |
|||
if [ -n "$TMUX" ]; then |
|||
export COLORTERM=rxvt |
|||
fi |
|||
</source> |
|||
:'''Note''': A better fix might be to do <code>mc -x</code> instead to force xterm mode. See [https://www.midnight-commander.org/ticket/2479 ticket 2479] and [https://www.midnight-commander.org/ticket/2978 ticket 2978] for more information. |
|||
{| class="wikitable" |
|||
|- |
|||
!key!!description |
|||
|- |
|||
|<tt>F10</tt>||Exit Midnight Commander |
|||
|- |
|||
|<tt>Esc-Tab</tt><br/><tt>Ctrl-N</tt>||Auto-Complete<br/>Auto-Complete (custom) |
|||
|- |
|||
|<tt>Ctrl-O</tt>||open sub-shell (with selected tab as current directory) |
|||
|- |
|||
|<tt>Ins</tt>||select highlighted file and move to next |
|||
|- |
|||
|<tt>Ctrl-\</tt>||Open directory menu |
|||
|- |
|||
|<tt>Ctrl-X D</tt>||Compare directories |
|||
|- |
|||
|<tt>Ctrl-R</tt>||Rescan (refresh panel contents) |
|||
|- |
|||
|<tt>Ctrl-O</tt>||Hide panels |
|||
|- |
|||
|<tt>Meta-*</tt>||Reverse selection |
|||
|- |
|||
|<tt>Alt-?</tt>||Find file |
|||
|- |
|||
|<tt>Ctrl-X Q</tt>||Quick view |
|||
|- |
|||
|<tt>Ctrl-X C</tt>||Change file and directory rights - chmod |
|||
|- |
|||
|<tt>Ctrl-X O</tt>||Change file and directory owner - chown |
|||
|- |
|||
|<tt>Ctrl-X S</tt>||Make symlink |
|||
|} |
|||
* Other frequently used keyboard shortcuts (custom shortcuts defined with ''Learn Keys...'' are <u>underlined</u>) |
|||
Obsolete configuration (for old version): |
|||
* '''mc''' will only save the option ini file if there is a directory <tt>~/.mc</tt> in home directory: |
|||
<source lang="bash" enclose="prevalid"> |
|||
mkdir ~/.mc |
|||
</source> |
|||
== Keyboard shortcuts == |
|||
Frequently used keyboard shortcuts (custom shortcuts defined with ''Learn Keys...'' are <u>underlined</u>): |
|||
<table> |
<table> |
||
<tr> |
<tr valign="top"> |
||
<td |
<td> |
||
'''General:'''<br/> |
'''General:'''<br/> |
||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width=" |
|width="150px"| |
||
<u>{{kb|C-k}}</u><br/> |
<u>{{kb|C-k}}</u><br/> |
||
<u>{{kb|C-l}}</u><br/> |
<u>{{kb|C-l}}</u><br/> |
||
{{kb|F10}}<br/> |
|||
{{kb|C-o}}<br/> |
|||
{{kb|C-x}}d<br/> |
|||
{{kb|C-r}}<br/> |
|||
{{kb|C-o}}<br/> |
|||
{{kb|M-*}}<br/> |
|||
{{kb|A-?}}<br/> |
|||
{{kb|C-x}}q<br/> |
|||
{{kb|C-x}}c<br/> |
|||
{{kb|C-x}}o<br/> |
|||
{{kb|C-x}}s |
|||
| |
| |
||
Down<br/> |
Down<br/> |
||
Up<br/> |
Up<br/> |
||
Exit Midnight Commander<br/> |
|||
open sub-shell (at current directory)<br/> |
|||
Compare directories<br/> |
|||
Rescan (refresh panel contents)<br/> |
|||
Hide panels<br/> |
|||
Reverse selection<br/> |
|||
Find file<br/> |
|||
'''Quick view / Quit quick view'''<br/> |
|||
Change file and directory rights - chmod<br/> |
|||
Change file and directory owner - chown<br/> |
|||
Make symlink |
|||
|} |
|} |
||
Line 71: | Line 89: | ||
{| class="wikitable" width="100%" |
{| class="wikitable" width="100%" |
||
|- |
|- |
||
|width=" |
|width="150px"| |
||
{{kb|A-Enter}}<br/> |
{{kb|A-Enter}}<br/> |
||
{{kb|C-S-Enter}}<br/> |
{{kb|C-S-Enter}}<br/> |
||
{{kb| |
{{kb|M-Tab}} ''or'' <u>{{kb|C-n}}</u><br/> |
||
{{kb|C-x}} t<br/> |
{{kb|C-x}} t<br/> |
||
{{kb|C-x}} {{kb|C-t}}<br/> |
{{kb|C-x}} {{kb|C-t}}<br/> |
||
{{kb|C-x}} p<br/> |
{{kb|C-x}} p<br/> |
||
{{kb|C-x}} |
{{kb|C-x}} {{kb|C-p}}<br/> |
||
{{kb|A-p}}<br/> |
{{kb|A-p}}<br/> |
||
{{kb|A-n}}<br/> |
{{kb|A-n}}<br/> |
||
{{kb|A-h}} |
{{kb|A-h}} |
||
| |
| |
||
Paste current selection<br/> |
|||
'''Paste fullpath current selection'''<br/> |
|||
Auto-complete<br/> |
'''Auto-complete'''<br/> |
||
'''Paste tagged files'''<br/> |
|||
'''Paste tagged files (other panel)'''<br/> |
|||
'''Paste current path'''<br/> |
|||
'''Paste current path (other panel)'''<br/> |
|||
Previous command in history<br/> |
Previous command in history<br/> |
||
Next command in history<br/> |
Next command in history<br/> |
||
Command history |
Command history |
||
|} |
|} |
||
</td> |
</td> |
||
<td> |
<td> |
||
Line 99: | Line 118: | ||
{| class="wikitable" |
{| class="wikitable" |
||
|- |
|- |
||
|width=" |
|width="150px"| |
||
{{kb|Tab}}<br/> |
{{kb|Tab}}<br/> |
||
{{kb| |
{{kb|Ins}} ''or'' {{kb|C-t}}<br/> |
||
{{kb|A-g}}<br/> |
{{kb|A-g}}<br/> |
||
{{kb|A-r}}<br/> |
{{kb|A-r}}<br/> |
||
Line 121: | Line 140: | ||
{{kb|End}} ''or'' {{kb|A->}}<br/> |
{{kb|End}} ''or'' {{kb|A->}}<br/> |
||
{{kb|C-PgUp}}<br/> |
{{kb|C-PgUp}}<br/> |
||
{{kb|C-PgDn}} |
{{kb|C-PgDn}} |
||
| |
| |
||
Panel switch<br/> |
Panel switch<br/> |
||
Line 144: | Line 163: | ||
End<br/> |
End<br/> |
||
Cd ..<br/> |
Cd ..<br/> |
||
Cd current selection |
Cd current selection |
||
|} |
|} |
||
</td> |
</td> |
||
Line 150: | Line 169: | ||
</table> |
</table> |
||
Some work-arounds / advices: |
|||
External links: |
|||
* '''Gnome-Terminal conflict''' — ''Gnome Terminal'' shortcuts conflict with ''MC''. Disable them in ''Keyboard shortcuts'' menu (''Terminal menu shortcut key'' (<tt>F10</tt>) and ''Menu Access Keys'' (<tt>A-h</tt>). |
|||
* [http://polishlinux.org/apps/cli/midnight-commander-in-action/ Cool review of mc in action] |
|||
* '''Auto-Complete does not work''' — The auto-complete shortcut {{kb|M-Tab}} (i.e. {{kb|Alt-Tab}}) doesn't work in graphical environment because it is used for switching between windows. As a replacement, one can use {{kb|Esc-Tab}}, or can define a new shortcut like {{kb|C-n}} (as in ''Vim'').<br/>Old version — This can be done with <tt>Options... → Learn Keys...</tt><br/>Newer version — The learn keys trick does not work anymore. Remove the learn key line from <tt>~/.mc/ini</tt> and instead edit all files <tt>/etc/mc/mc.keymap*</tt> as follows: |
|||
* [http://www.nongnu.org/gcmd/ The GNOME Commander], a X alternative of <tt>mc</tt> under Gnome |
|||
:For ''mc version 4.7'': |
|||
* [http://www.krusader.org/index.php Krusader], a X alternative of <tt>mc</tt> under KDE |
|||
<pre>PanelMoveDown = down |
|||
... |
|||
InputComplete = alt-tab; ctrl-n |
|||
... |
|||
TreeMoveDown = down |
|||
</pre> |
|||
:For ''mc version 4.8'' and above: |
|||
<pre>[panel] |
|||
... |
|||
MoveDown = down |
|||
... |
|||
[input] |
|||
... |
|||
Complete = alt-tab; ctrl-n |
|||
... |
|||
</pre> |
|||
or via command-line: |
|||
<source lang=bash> |
|||
sudo sed -ri 's/; ctrl-n//' /etc/mc/mc*.keymap |
|||
sudo sed -ri 's/Complete.*/Complete = alt-tab; ctrl-n' /etc/mc/mc*.keymap |
|||
</source> |
|||
* '''Lynx motion''' — This is a nice option to enable in the configuration menu. When enabled, enter a directory with {{kb|right}} and exit a directory with {{kb|left}}. |
|||
== Official repository == |
|||
Besides Ubuntu repository, the official one is [http://www.midnight-commander.org/wiki/Binaries here]. To add it: |
|||
<source lang="bash"> |
|||
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F82FBD49 |
|||
</source> |
|||
Add file <tt>/etc/apt/sources.list.d</tt>: |
|||
deb http://ppa.launchpad.net/zyv/ppa/ubuntu lucid main |
|||
deb-src http://ppa.launchpad.net/zyv/ppa/ubuntu lucid main |
|||
Then upgrade if needed: |
|||
<source lang="bash"> |
|||
sudo apt-get update |
|||
sudo apt-get upgrade |
|||
</source> |
|||
== Troubleshoot == |
|||
=== MC shows "press any key to continue..." when TERM=gnome-256color === |
|||
Setting TERM is necessary to fix issues in Neovim. |
|||
* Workaround: start mc with <code>mc -x</code> to force xterm mode: |
|||
<source lang="bash"> |
|||
# MC - Force xterm mode if TERM=gnome-256color |
|||
[ "$TERM" = "gnome-256color" ] && alias mc='mc -x' |
|||
</source> |
|||
* '''Update''': we don't change TERM anymore, so this fix is no longer necessary. |
|||
=== Ctrl-Shift-Enter not working in Wayland === |
|||
This happens in latest Debian (Buster), and is due to Wayland security model [https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=899376]. |
|||
As a fix, we can use {{kb|Alt-M}} instead [https://unix.stackexchange.com/questions/414413/ctrl-enter-for-midnight-commander-not-working-in-x-terminals-in-fedora-working/505969#505969]: |
|||
<source lang="bash"> |
|||
sudo sed -ri '/PutCurrentFullSelected/s/=( alt-m;)?/= alt-m;/' /etc/mc/mc.default.keymap |
|||
sudo sed -ri '/Mail = alt-m/s/= alt-m/=/;' /etc/mc/mc.default.keymap |
|||
</source> |
|||
=== Ctrl-Shift-E not working === |
|||
In recent Gnome, {{kb|Ctrl-Shift-E}} is now assigned to emoji input. |
|||
To remove [https://bugs.launchpad.net/ubuntu/+source/terminator/+bug/1738500]: |
|||
* Start <code>ibus-setup</code> |
|||
* Go to Emoji, click ... for emoji, then delete. |
Latest revision as of 16:45, 10 October 2020
mc or Midnight Commander is a powerful file manager working in a shell terminal.
Links
- Cool review of mc in action
- The GNOME Commander, a X alternative of mc under Gnome
- Krusader, a X alternative of mc under KDE
- Color schemes
VirtualFS
- Shell filesystem: /#sh:[user@]machine[:options]/[remote_dir]
Configuration
- To use vi as standard editor/viewer
- First menu Options → Configuration... → uncheck use internal edIt and Use internal view.
- Next, at the end of file .mc/bindings:
default/*
Open=
View=view %f
Edit=%var{EDITOR:vi} %f
- Edit /etc/mc/mc.keymap* to use C-n for Auto-Complete (instead of Alt-Tab that does not work in graphical environment) (see below)
- Check complete: show all (so that selection box is shown on first ambiguity)
- To have common history between mc sub-shell and parent shell: [1]:
alias mc='PROMPT_COMMAND="history -a; history -r" mc; history -r'
- Add the following to ~/.bash_profile and ~/.profile to Meta-key (Alt) not working and Midnight Commander displays
Press any key...
after each command when in tmux session [2]:
# This fix meta-key support and stop mc displaying "Press any key..." in tmux session
if [ $TERM = "screen" ]; then
export TERM=xterm
fi
if [ -n "$TMUX" ]; then
export COLORTERM=rxvt
fi
- Note: A better fix might be to do
mc -x
instead to force xterm mode. See ticket 2479 and ticket 2978 for more information.
Obsolete configuration (for old version):
- mc will only save the option ini file if there is a directory ~/.mc in home directory:
mkdir ~/.mc
Keyboard shortcuts
Frequently used keyboard shortcuts (custom shortcuts defined with Learn Keys... are underlined):
General:
Shell Command Line
|
Directory panels
|
Some work-arounds / advices:
- Gnome-Terminal conflict — Gnome Terminal shortcuts conflict with MC. Disable them in Keyboard shortcuts menu (Terminal menu shortcut key (F10) and Menu Access Keys (A-h).
- Auto-Complete does not work — The auto-complete shortcut M-Tab (i.e. Alt-Tab) doesn't work in graphical environment because it is used for switching between windows. As a replacement, one can use Esc-Tab, or can define a new shortcut like C-n (as in Vim).
Old version — This can be done with Options... → Learn Keys...
Newer version — The learn keys trick does not work anymore. Remove the learn key line from ~/.mc/ini and instead edit all files /etc/mc/mc.keymap* as follows:
- For mc version 4.7:
PanelMoveDown = down ... InputComplete = alt-tab; ctrl-n ... TreeMoveDown = down
- For mc version 4.8 and above:
[panel] ... MoveDown = down ... [input] ... Complete = alt-tab; ctrl-n ...
or via command-line:
sudo sed -ri 's/; ctrl-n//' /etc/mc/mc*.keymap
sudo sed -ri 's/Complete.*/Complete = alt-tab; ctrl-n' /etc/mc/mc*.keymap
- Lynx motion — This is a nice option to enable in the configuration menu. When enabled, enter a directory with right and exit a directory with left.
Official repository
Besides Ubuntu repository, the official one is here. To add it:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F82FBD49
Add file /etc/apt/sources.list.d:
deb http://ppa.launchpad.net/zyv/ppa/ubuntu lucid main deb-src http://ppa.launchpad.net/zyv/ppa/ubuntu lucid main
Then upgrade if needed:
sudo apt-get update
sudo apt-get upgrade
Troubleshoot
MC shows "press any key to continue..." when TERM=gnome-256color
Setting TERM is necessary to fix issues in Neovim.
- Workaround: start mc with
mc -x
to force xterm mode:
# MC - Force xterm mode if TERM=gnome-256color
[ "$TERM" = "gnome-256color" ] && alias mc='mc -x'
- Update: we don't change TERM anymore, so this fix is no longer necessary.
Ctrl-Shift-Enter not working in Wayland
This happens in latest Debian (Buster), and is due to Wayland security model [3].
As a fix, we can use Alt-M instead [4]:
sudo sed -ri '/PutCurrentFullSelected/s/=( alt-m;)?/= alt-m;/' /etc/mc/mc.default.keymap
sudo sed -ri '/Mail = alt-m/s/= alt-m/=/;' /etc/mc/mc.default.keymap
Ctrl-Shift-E not working
In recent Gnome, Ctrl-Shift-E is now assigned to emoji input.
To remove [5]:
- Start
ibus-setup
- Go to Emoji, click ... for emoji, then delete.