Midnight Commander: Difference between revisions

From miki
Jump to navigation Jump to search
Line 53: Line 53:
[ "$TERM" = "gnome-256color" ] && alias mc='mc -x'
[ "$TERM" = "gnome-256color" ] && alias mc='mc -x'
</source>
</source>
* '''Update''': we don't change TERM anymore, so this fix is no longer necessary.


== Keyboard shortcuts ==
== Keyboard shortcuts ==

Revision as of 04:40, 23 June 2017

mc or Midnight Commander is a powerful file manager working in a shell terminal.

Links

VirtualFS

  • Shell filesystem: /#sh:[user@]machine[:options]/[remote_dir]

Configuration

  • To use vi as standard editor/viewer
First menu OptionsConfiguration...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

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.

Keyboard shortcuts

Frequently used keyboard shortcuts (custom shortcuts defined with Learn Keys... are underlined):

General:

C-k
C-l
F10
C-o
C-xd
C-r
C-o
M-*
A-?
C-xq
C-xc
C-xo
C-xs

Down
Up
Exit Midnight Commander
open sub-shell (at current directory)
Compare directories
Rescan (refresh panel contents)
Hide panels
Reverse selection
Find file
Quick view / Quit quick view
Change file and directory rights - chmod
Change file and directory owner - chown
Make symlink

Shell Command Line

A-Enter
C-S-Enter
M-Tab or C-n
C-x t
C-x C-t
C-x p
C-x C-p
A-p
A-n
A-h

Paste current selection
Paste fullpath current selection
Auto-complete
Paste tagged files
Paste tagged files (other panel)
Paste current path
Paste current path (other panel)
Previous command in history
Next command in history
Command history

Directory panels

Tab
Ins or C-t
A-g
A-r
A-j
C-s A-s
A-t
C-\
C-x h
+
\
A-o
A-i
A-y
A-u
A-S-h
PgDn or C-v
PgUp or A-v
Home or A-<
End or A->
C-PgUp
C-PgDn

Panel switch
Tag/untag
Select top file
Select middle file
Select bottom file
Filename search
Toggle current display listing
Show directory hotlist
Quick add to directory hostlist
Group select
Group unselect
Load directory/parent directory in other panel
Duplicate current panel
Previous directory in history
Next directory in history
View history
PgDn
PgUp
Home
End
Cd ..
Cd current selection

Some work-arounds / advices:

  • Gnome-Terminal conflictGnome 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