Difference between revisions of "Nnn"

From ArchWiki
Jump to navigation Jump to search
m (Expanded introduction)
m (Fixed article)
Line 15: Line 15:
 
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. It supports contexts, bookmarks, multiple sorting options, SSHFS, batch operations on selections (a group of selected files) and a lot more.
 
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. It supports 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. It integrates seamlessly with the Desktop Environment at minimal to zero configuration.
+
Despite its capabilities, nnn is designed to be easy to use. It integrates seamlessly with the Desktop Environment at zero to minimal configuration.
  
 
== Installation ==
 
== Installation ==

Revision as of 01:49, 17 July 2019

nnn is a very fast and minimalist terminal file manager written in C. It is an excellent choice if you need a file manager on multiple machines, as it is highly portable and doesn't require exotic dependencies. It is a full-featured file manager and is easily extensible via its plugin system where you can add your own scripts alongside already available plugins. A (neo)vim plugin is also available.

In addition to being a file manager, nnn is also a disk usage analyzer, a fuzzy app launcher, a batch file renamer and a file picker.

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. It supports 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. It integrates seamlessly with the Desktop Environment at zero to minimal configuration.

Installation

nnn can be installed with the nnn package.

Usage

nnn can be controlled with the vim-like characters hjkl or the arrow keys. Don't memorize keys. Arrows, / and q suffice. Press ? for help on keyboard shortcuts anytime.

Configuration

nnn is configured via environment variables, by editing ~/.bashrc. For detailed information on these settings see the included, well-documented man page man nnn as well as the additional configurations on the nnn wiki.

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

~/.bashrc
export NNN_BMS='d:~/Documents;u:/home/user/Cam Uploads;D:~/Downloads/'
export NNN_USE_EDITOR=1                                 # Use the $EDITOR when opening text files
export NNN_NO_AUTOSELECT=1                              # Do not auto select in navigate-as-you-type-mode
export NNN_NOTE="$HOME/mynotes"                         # If you already have your own notebook, 
export NNN_OPS_PROG=1                                   # If you have installed advcp from the AUR. Giving you progress bars for mv and cp
export NNN_SSHFS_OPTS="sshfs -o follow_symlinks"        # make sshfs follow symlinks on the remote
alias ncp="cat ~/.config/nnn/.selection

The most important setting would be the NNN_BMS variable which lets you choose shortcuts to quickly jump to your bookmarked directories. By default they are reached with <leader-key> which is set to , (a comma). In the example configuration hitting the keys: ,D would result in nnn jumping into ~/Downloads. But all of these are optional, nnn will consistently behave the same on all of your machines.

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)

To exit nnn and cd to the current working directory, you could add the following to your ~/.bashrc.

Note: You can find similar scripts for various shells here.
~/.bashrc
n()
{
    export NNN_TMPFILE=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.lastd

    nnn "$@"

    if [ -f $NNN_TMPFILE ]; then
            . $NNN_TMPFILE
            rm -f $NNN_TMPFILE > /dev/null
    fi
}

And then start another terminal or run:

source ~/.bashrc

This will cause your shell to reload the ~/.bashrc.

From now on you can run nnn as:

$ n

Which will correctly handle CTRL-G upon exiting nnn.

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