nnn

From ArchWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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

nnn can be installed with the nnn package.

Usage

nnn can be controlled with the vim-like characters 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, typically by appending them to ~/.bashrc. For detailed information on these settings see the man page nnn(1) as well as the nnn wiki.

Here is an example configuration you can add to your ~/.bashrc:

~/.bashrc
export NNN_BMS='d:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/'
export NNN_SSHFS="sshfs -o follow_symlinks"        # make sshfs follow symlinks on the remote
export NNN_COLORS="2136"                           # use a different color for each context
export 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_zsh ]; then
    source /usr/share/nnn/quitcd/quitcd.bash_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 -- "$@"

And then trigger it by hitting 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