nnn

From ArchWiki

nnn (also stylized as n³) is a portable terminal file manager written in C. It is easily extensible via its flat text plugin system where you can add your own language-agnostic scripts alongside already available plugins, including a (neo)vim plugin.

nnn features native archiving/decompression to and from commonly installed formats such as xz, disk usage analysis and a fuzzy app launcher, a batch file renamer and a file picker through its plugin architecture. nnn supports instant search-as-you-type with regex (or simple string) filters and a navigate-as-you-type mode for continuous navigation in filter mode with directory auto-select. Also supported are contexts, bookmarks, multiple sorting options, SSHFS, batch operations on selections (a group of selected files) and a lot more.

Despite its capabilities, nnn is designed to be easy to use and is configured by way of environment variables without the use of a configuration file.

Installation

Install the nnn package, or nnn-gitAUR for the development version.

Usage

nnn can be controlled with the vi-like keys hjkl or the arrow keys. Do not memorize keys: arrows, / and q suffice. Press ? for help on keyboard shortcuts anytime.

Configuration

nnn is configured via environment variables. For detailed information on these settings, see nnn(1) as well as the nnn wiki.

NNN_BMS='d:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/'
NNN_SSHFS="sshfs -o follow_symlinks"        # make sshfs follow symlinks on the remote
NNN_COLORS="2136"                           # use a different color for each context
NNN_TRASH=1                                 # trash (needs trash-cli) instead of delete
Note: If you start nnn via nnn.desktop from a desktop environment started from a display manager, .bashrc may not be sourced. In this case, see the upstream instructions for desktop integration.

One of the more useful settings is the NNN_BMS variable which lets you choose shortcuts to quickly jump to your bookmarked directories. They are reached with b followed by one of the letters that you have specified. In the example configuration hitting the keys bD would result in nnn jumping into ~/Downloads. But all of these are optional, nnn will consistently behave the same on all of your machines.

Get selected files in terminal

To get a list of the files you have selected in nnn one could create the following alias:

~/.bashrc
alias ncp="cat ${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection} | tr '\0' '\n'"

which later could be used to pipe the selected files to other tools.

Indicate depth level within nnn shells

If you use ! to spawn a shell in the current directory, it could be nice to add:

~/.bashrc
[ -n "$NNNLVL" ] && PS1="N$NNNLVL $PS1"

To have your prompt indicate that you are within a shell that will return you to nnn when you are done.

This together with #cd on quit (Ctrl-G) becomes a powerful combination.

cd on quit (Ctrl-G)

Add the following to your .bashrc/.zshrc

~/.bashrc or ~/.zshrc
if [ -f /usr/share/nnn/quitcd/quitcd.bash_sh_zsh ]; then
    source /usr/share/nnn/quitcd/quitcd.bash_sh_zsh
fi

And run the n command instead of nnn (more precisely the n bash function).

Also see the nnn wiki.

Add your own plugins

You can run your own plugins by putting them in ${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins. For example you could create a executable shell script

${XDG_CONFIG_HOME:-$HOME/.config}/nnn/plugins/git-changes
#!/usr/bin/env sh
git log -p -- "$@"

Set the environment variable NNN_PLUG='R:git-changes' and then trigger it by pressing ;R and selecting git-changes which will conveniently show the git log of changes to the particular file along with the code for a quick and easy review.

See also