Skip to content

Instantly share code, notes, and snippets.

@moalex
Created May 31, 2021 12:02
Show Gist options
  • Save moalex/b823da9905cfac65abbdf62373d6b6bb to your computer and use it in GitHub Desktop.
Save moalex/b823da9905cfac65abbdf62373d6b6bb to your computer and use it in GitHub Desktop.
nnn-wiki

Dependencies

A curses library with wide char support (e.g. ncursesw), libc and libreadline (optional).

Utility deps Install? Operation
xdg-open (Linux), open(1) (macOS), cygstart (Cygwin), open (Haiku) base default opener
file, coreutils (cp, mv, rm), xargs, sed (gnu-sed on macOS) base file type, copy, (re)move
tar, (un)zip [atool/bsdtar for more formats] base create, list, extract bzip2, (g)zip, tar
archivemount, fusermount(3)/umount (macOS) optional (un)mount archives
sshfs, rclone, fusermount(3)/umount (macOS) optional (un)mount remotes
gio trash, trash-cli optional trash files (default: rm -rf)
vlock (Linux), bashlock (macOS), lock(1) (BSD), peaclock (Haiku), $NNN_LOCKER optional lock terminal
advcpmv (Linux) (integration) optional copy, move progress
fortune optional random quotes in help
$VISUAL (else $EDITOR), $PAGER, $SHELL optional fallback vi, less, sh

Installation

TL;DR: Can't install packages? Get the statically linked binary from the latest release.

From a package manager

Packaging status (expand) Packaging status


Packaging status

Unlisted packagers:


● CentOS (yum --enablerepo=epel install nnn)
● iSH (apk add nnn)
Milis Linux (mps kur nnn)
NuTyX (cards install nnn)
Sailfish OS (devel-su zypper install nnn)
Source Mage (cast nnn)

Release packages

Packages for Arch Linux, CentOS, Debian, Fedora, Ubuntu and a static binary are generated with the latest release.

From source

Download the latest release or clone this repo (risky), install deps and compile. On Ubuntu 18.04:

sudo apt-get install pkg-config libncursesw5-dev libreadline-dev
sudo make strip install

PREFIX is supported, in case you want to install to a different location.

See the developer guides for source verification, platform-specific notes and other tips.

Shell completion

Completion scripts for Bash, Fish and Zsh are available. Refer to your shell's manual to install.

Configuration

The new colorscheme (config NNN_FCOLORS) - a feast for your eyes!

There is no config file. Associated files are at

${XDG_CONFIG_HOME:-$HOME/.config}/nnn/

Use plugin nbak to backup configuration.

nnn supports a few optional (set if you need) environment variables.

Example export Description
NNN_OPTS="cEnrx" binary options to nnn
NNN_OPENER="/path/to/custom/opener" custom opener (see plugin nuke)
NNN_BMS="d:$HOME/Documents;D:$HOME/Docs archive/" 1 key-bookmark pairs
NNN_PLUG='o:fzopen;m:nmount;x:_chmod +x $nnn' 1 key-plugin (or cmd) pairs
NNN_ARCHIVE="\\.(7z|bz2|gz|tar|tgz|zip)$" 2 archives [default: bzip2, (g)zip, tar]
NNN_COLORS='1234' (/'#0a1b2c3d'/'#0a1b2c3d;1234') 3 5 context colors [default: '4444' (blue)]
NNN_FCOLORS='c1e2272e006033f7c6d6abc4' 4 file-specific colors
NNN_SSHFS='sshfs -o reconnect,idmap=user' 5 custom SSHFS cmd
NNN_RCLONE='rclone mount --read-only' 5 custom rclone cmd
NNN_TRASH=n (n=1: trash-cli, n=2: gio trash) use desktop Trash [default: delete]
NNN_SEL='/tmp/.sel' custom selection file
NNN_FIFO='/tmp/nnn.fifo' 6 FIFO to write hovered file path to
NNN_LOCKER='saidar -c' terminal locker
NNN_MCLICK='^R' 7 key emulated by middle mouse click
NO_COLOR=1 8 disable ANSI color output
  1. Key-bookmark and key-plugin pairs are listed in the help and config screen (key ?).

  2. With atool or bsdtar installed you can have:

    export NNN_ARCHIVE="\\.(7z|a|ace|alz|arc|arj|bz|bz2|cab|cpio|deb|gz|jar|lha|lz|lzh|lzma|lzo|rar|rpm|rz|t7z|tar|tbz|tbz2|tgz|tlz|txz|tZ|tzo|war|xpi|xz|Z|zip)$"
    

    bsdtar can extract, list and archivemount can mount ISO 9660 cdrom images (extn: iso).

  3. Understands 8 color, xterm 256 color or both.

Hexadecimal numbers representing xterm 256 colors, note that the width has to be 2, e.g. "5" becomes "05"

  • 8 colors numbers: 0-black, 1-red, 2-green, 3-yellow, 4-blue (default), 5-magenta, 6-cyan, 7-white.
  • To specify xterm 256 color hex numbers, prefix with # (2 symbols per context).
  • To specify both, export 256 color hex numbers followed by 8 color number as fallback, separated by ;.
  1. Specify file-specific colors in xterm 256 color hex numbers (2 hex symbols per color).

    Order is strict, use 00 to omit/use default terminal color. Defaults:

    Order Hex Color
    Block device c1 DarkSeaGreen1
    Char device e2 Yellow1
    Directory 27 DeepSkyBlue1
    Executable 2e Green1
    Regular 00 Normal
    Hard link 60 Plum4
    Symbolic link 33 Cyan1
    Missing OR file details f7 Grey62
    Orphaned symbolic link c6 DeepPink1
    FIFO d6 Orange1
    Socket ab MediumOrchid1
    Unknown OR 0B regular/exe c4 Red1
    • If the terminal supports xterm 256 colors or more, file-specific colors will be rendered.
    • To force the 8-color scheme use option -C.
    • If xterm 256 colors aren't supported, 8-color scheme will be used.
    • More Themes.
  2. nnn v2.9 and below have NNN_CONTEXT_COLORS, NNN_SSHFS_OPTS and NNN_RCLONE_OPTS.

  3. If the FIFO file doesn't exist it will be created, but it will never be removed.

  4. Only the first character is considered if not a Ctrl-key combo.

  5. Overridden by NNN_COLORS.

Program options

usage: nnn [OPTIONS] [PATH]

The missing terminal file manager for X.

positional args:
  PATH   start dir/file [default: .]

optional args:
 -a      auto NNN_FIFO
 -A      no dir auto-select
 -b key  open bookmark key (trumps -s/S)
 -c      cli-only NNN_OPENER (trumps -e)
 -C      8-color scheme
 -d      detail mode
 -D      dirs in context color
 -e      text in $VISUAL/$EDITOR/vi
 -E      internal edits in EDITOR
 -f      use readline history file
 -F      show fortune
 -g      regex filters
 -H      show hidden files
 -J      no auto-proceed on select
 -K      detect key collision
 -l val  set scroll lines
 -n      type-to-nav mode
 -o      open files only on Enter
 -p file selection file [stdout if '-']
 -P key  run plugin key
 -Q      no quit confirmation
 -r      use advcpmv patched cp, mv
 -R      no rollover at edges
 -s name load session by name
 -S      persistent session
 -t secs timeout to lock
 -T key  sort order [a/d/e/r/s/t/v]
 -u      use selection (no prompt)
 -U      show user and group
 -V      show version
 -w      place HW cursor on hovered
 -x      notis, selection sync, xterm title
 -h      show help

Keyboard, mouse

The list below is from master. Press ? in nnn to see the keybinds in your installed version.

 NAVIGATION
         Up k  Up                PgUp ^U  Scroll up
         Dn j  Down              PgDn ^D  Scroll down
         Lt h  Parent            ~ ` @ -  ~, /, start, prev
     Ret Rt l  Open                    '  First file/match
         g ^A  Top                     .  Toggle hidden
         G ^E  End                     +  Toggle auto-advance
         b ^/  Bookmark key            ,  Mark CWD
          1-4  Context 1-4       (Sh)Tab  Cycle/new context
          Esc  Send to FIFO           ^L  Redraw
            Q  Pick/err, quit         ^G  QuitCD
            q  Quit context      2Esc ^Q  Quit
            ?  Help, conf
 FILTER & PROMPT
            /  Filter            Alt+Esc  Unfilter, quit context
          Esc  Exit prompt            ^L  Clear prompt/last filter
           ^N  Toggle type-to-nav 
 FILES
         o ^O  Open with...            n  Create new/link
         f ^F  File details            d  Detail mode toggle
           ^R  Rename/dup              r  Batch rename
            z  Archive                 e  Edit file
            *  Toggle exe              >  Export list
     Space ^J  (Un)select            m-m  Mark range/clear sel
            a  Select all              A  Invert sel
         p ^P  Copy sel here        w ^W  Cp/mv sel as
         v ^V  Move sel here           E  Edit sel
         x ^X  Delete
 MISC
        Alt ;  Select plugin           =  Launch app
         ! ^]  Shell                   ]  Cmd prompt
            c  Connect remote          u  Unmount remote/archive
         t ^T  Sort toggles            s  Manage session
            T  Set time type           0  Lock

Notes:

  1. Shift-TAB attempts to create a new context, and reverse cycles when all contexts are active.
  2. At the filter prompt, ^L toggles last filter and unfilter. If no last filter, exits filter mode and redraws.
  3. Q quits with EXIT_FAILURE if no selection, else prints the selection to stdout and quits with EXIT_SUCCESS.
  4. Help & settings, file details and archive listing are shown in the $PAGER.
  5. To change shortcuts modify key bindings in nnn.h and compile. Option -K detects collisions.

Graphical map

nnn QWERTY map

(CC BY-SA Léo Villeveygoux, based on Qwerty.svg)

SVG version

Mouse

Mouse click Function
Left single on context number Visit context
Left single on current path Visit parent
Left single/double on last 2 rows Toggle type-to-nav
Left single Select context or entry
Left double Select context or open entry
Right single Add entry to selection
Middle single User configured

Broken control keybind

Some control keybinds may not work if they are mapped by stty. To confirm, run stty -a and look for keybind conflicts. Some common ones are: ^Q (start), ^S (stop), ^V (lnext).

To remove the stty mapping:

stty start undef
stty stop undef
stty lnext undef

Symbols

File indicators

Listing 1Listing 2
Indicator File type
/ Directory
* Executable
| Fifo
= Socket
Indicator File type
@ Symlink to file
b Block device
c Character device
? Unknown

Note:

  • All links (hard/sym) are dimmed.

Status bar symbols

Symbol Meaning
x/y current file num / total
+/*(n) selection mode on/range selection on (buffered selected count) [reversed]
H hidden files are listed
M modification time sorted
A access time sorted
C change time sorted
S size sorted
E file extension sorted
V version sorted
R reverse sorted
du disk usage
au apparent disk usage
-> symbolic link target
n-n num hard links - inode number

File size

The minimum file size unit is byte (B). The rest are K, M, G, T, P, E, Z, Y (powers of 1024), same as the default units in ls.

Help

nnn -h
man nnn

To lookup keyboard shortcuts at runtime, press ?.

user1: How it compares to Midnight Commander ?
user2: It works in daylight too.
         - from a reddit conversation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment