Skip to content
Mischievous Meerkat edited this page Oct 11, 2020 · 445 revisions

Asciicast

Project dir in preview

Welcome to the nnn Wiki! It's editable. Feel free to add to the knowledge base.

nnn (or ) is a recursive acronym from Nnn's Not Noice!

Looking for a list of features or quickstart guide? Visit the project home.

Contexts

Open multiple locations with 4 contexts. The status is shown in the top left corner:

  • the current context is in reverse video
  • other active contexts are underlined
  • rest are inactive

Cycle contexts using Tab or Shift+Tab. A new context copies the state of the previous context.

Use context-specific colors (see configuration NNN_COLORS) to identify each context easily.

Dual pane

The nnn way is to work with multiple contexts using Tab or Shift+Tab.

For dual pane, use a terminal multiplexer e.g., to open 2 instances in dvtm, run:

dvtm n n

You can also have an alias:

alias n2="dvtm n n"

or a Bash function (with ^\ as dvtm modifier) to handle arguments:

n2 ()
{
    dvtm -m '^\' "nnn -nr $@" "nnn -nr $@"
}

Sessions

Sessions are a way to save and restore states of work. A session stores the settings and contexts. All the session files are located in the ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/sessions directory by the session name.

Sessions can be loaded dynamically at runtime or with a program option.

Note: When a session is loaded dynamically, the last working session is saved automatically to a dedicated -- "last session" -- session file. The "last session" is also used in persistent session mode.

Filters

Filters are strings (or regex patterns) to find matching entries in the current directory instantly (search-as-you-type). Matches are case-insensitive by default. The last filter in each context is persisted at runtime or in saved sessions.

Special keys at filter prompt

Key Function
^char Usual keybind functionality
Esc Exit filter prompt but skip dir refresh
Alt+Esc Exit filter prompt and refresh dir (same as Esc^L)

Special keys at empty filter prompt:

Key Function
? Show help and config screen
/ Toggle between string and regex
: Toggle case-sensitivity
^L Clear filter (if prompt is non-empty)
OR apply last filter

Additional special keys at empty filter prompt in type-to-nav mode:

Listing 1 Listing 2
Key Function
' Go to first file/match
+ Toggle auto-advance
, Mark CWD
- Go to last visited dir
. Show hidden files
; Run a plugin by its key
Key Function
= Launch a GUI application
> Export file list
@ Visit start dir
] Show command prompt
` Visit /
~ Go HOME

Common regex use cases

  • to list all matches starting with the filter expression, start with a ^ (caret)
  • type \.mkv to list all MKV files
  • use .* to match any character (sort of fuzzy search)
  • exclude filenames having nnn (with PCRE): ^(?!nnn)

Limitation

Use regex for case-sensitive filtering with wide chars as the function strcasestr (used for string filters) does not work with multibyte locales (ref1, ref2).

Type-to-nav

In this mode directories are opened in filter mode, allowing continuous navigation.

When there's a unique match and it's a directory, nnn auto selects the directory and enters it in this mode. Program option -A disables this.

To start in type-to-nav mode, use the program option -n or press ^N.

Selection

nnn allows file selection across directories and contexts!

There are 3 groups of keybinds to add files to selection:

  1. hovered file selection toggle
    • deselects if + is visible before the entry, else adds to selection
  2. add a range of files to selection
    • repeat the range key on the same entry twice to clear selection completely
  3. add all files in the current directory to selection

A selection can be edited, copied, moved, removed, archived or linked. Example workflow to copy or move some files:

  • add files from source dirs (you can select files from multiple dirs in nnn) to selection
  • navigate to a target directory
  • use ^P (cp) or ^V (mv) to copy or move the selected files

Absolute paths of the selected files are copied to .selection file in the config directory. The selection file is shared between multiple program instances. The most recent instance writing to the file overwrites the entries from earlier writes. If you have 2 instances of nnn open in 2 panes of a terminal multiplexer, you can select in one pane and use the selection (e.g. to copy or move) in the other pane (if the instance doesn't have any local selection already).

nnn clears the selection after file removal, batch-rename and link creation with selection. However, it is retained after archive creation with selection as the user may want to delete the archived files next.

Editing selection

To edit the selection use the edit selection key. Use this key to remove a file from selection after you navigate away from its directory or remove duplicates. Editing doesn't end the selection mode. You can add more files to the selection and edit the list again. If no file is selected in the current session, this option attempts to list the selection file.

File paths in selection to system clipboard

Use the program option -x to copy selection to the system clipboard. You must have plugins installed.

Grab file paths in selection manually

Many plugins use this method. The file paths are NUL-terminated, so additional processing is required to make them usable.

To run ls -l on the file paths in selection:

xargs -0 ls -l < "${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection"

An special variable may be handy:

export sel=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection

so you can easily handle files together (even at the nnn command prompt!):

xargs -0 ls -l < $sel // compare 2 selected files

Notes:

  1. The selection file can be directly edited to remove any entries but it's not recommended.
  2. If an already selected file doesn't have the + symbol before it (say, on a directory refresh or after navigating away and back to the dir), the selection toggle key will add it again.
  3. Window managers like i3/sway re-dimensions window and forces redraw when opening a file. So the + symbol disappears. To get rid of this use a CLI opener like nuke. For example, when opening and renaming files with nuke, the images are opened in the terminal in viu and there is no window-manager redraw involved. See issue #464.

Find and list

There are two ways to search and list:

  • feed a list of file paths as input
  • search using a plugin (e.g. finder) and list the results

File paths must be NUL-separated ('\0'). Paths can be relative to the current directory or absolute. Invalid paths in the input are ignored. Input limit is 65,536 paths or 256 MiB of data.

To list the input stream, start nnn by writing to its standard input. E.g., to list files in current directory larger than 1M:

find -maxdepth 1 -size +1M -print0 | nnn
# fd -d 2 -S +1M -0 | nnn

or redirect a list from a file:

nnn < files.txt

Handy bash/zsh shell function to list files by mime-type in current directory:

# to show video files, run: list video

list ()                                                                                                    
{
    find . -maxdepth 1 | file -if- | grep "$1" | awk -F: '{printf "%s\0", $1}' | nnn
    # fd -d 1 | file -if- | grep "$1" | awk -F: '{printf "%s\0", $1}' | nnn
}

A temporary directory will be created containing symlinks to the given paths. Any action performed on these symlinks will be performed only on their targets, after which they might become invalid.

Right or l on a symlink inside the listing dir takes to the target file. Press - to return to the listing dir. Press Enter to open the symlink.

Prompts

The prompts (except the filter prompt) support readline-like command-line shortcuts. Enter or ^D at the empty prompt (except the filter prompt) exits the prompt.

Key ^L clears and Esc exits all prompts.

The run & exit command prompt understands environment variables (like $PWD). Refer to your shell's documentation (e.g. BASH_ENV for bash, ~/.zshenv for zsh) to use aliases and functions. To fuzzy-select commands from your shell history at the command prompt and issue them after editing (like fc), copy the plugin fzhist (as h maybe?) in your $PATH.

The special variable $nnn denotes the hovered file name. It is accessible from the command prompt or a spawned shell.

All binary questions are confirmed by y or Y.

Design

nnn (the core C utility) is, generally speaking, feature-restricted. It includes features which you really need so it can remain light enough to finish your workflow accurately before your train of thought is lost.

nnn supports plugins to extend its capabilities.

Here's a list of the design principles driving the core nnn program:

  1. nnn complements X, doesn't substitute it
    • Brings the best of CLI to a GUI user
    • Doesn't expect the user to abandon GUI (the GUI is well-established for a reason)
    • Zero-config comfort-zone for GUI users out of the box
  2. Quick and distraction-free workflows
  3. Clean and clutter-free single-window view focused on content
    • Easily switch context/tabs with (Sh)TAB
  4. Only directories in color, no icons
    • To search/group by extension, use filter or sort by extension option
  5. Support external or plugin-based previewers by writing the the hovered file path to a custom FIFO.
  6. One utility instead of multiple utilities for related tasks e.g.
    • file management, batch rename, disk usage analysis, launching apps etc.
  7. No configuration file and few environment variables
  8. Stay portable - very limited library dependencies
    • support compiling out features
  9. Use a standard desktop opener to handle file associations
  10. Analyze disk usage within the same filesystem, do not follow symbolic links
  11. Case-insensitive alphabetic content listing instead of all uppercase first
  12. Directories first in all modes (even in disk usage analyzer mode)
  13. No navigation restriction with relative paths (let permissions handle it)
  14. Directory updates are disabled in the following modes:
    • disk usage: re-scans are issued on every change in dir
    • filter mode: content refresh is very disruptive in the workflow
  15. Limited (4) number of contexts; for more, use another instance
    • file paths copy-paste should work seamlessly between contexts and instances of nnn
  16. Scan each directory on visit (even in disk usage analyzer mode) rather than storing all the information from the first scan. This keeps the information up to date. To compensate, use fast re-scan with highly optimized algorithms.
Clone this wiki locally