Skip to content

Power toys

Mischievous Meerkat edited this page Apr 9, 2020 · 4 revisions

1. Redirect selection to a command

nnn allows users to select a file at a time, a range of files or all files in a directory together. Once you are done selecting, you can run a command on all the files by using the selection file as input:

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

If you are using this frequently, have a shortcut in your rc file:

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

and simplify the command as:

xargs -0 ls -l < $sel

Many plugins work this way!

2. Pin a frequently visited directory

If you need to repeat a directory repeatedly, you can pin it during a session using the shortcut ,. When you have a pinned directory, pressing the bookmark key (b or ^/) will list , as the first key:

bookmark keys: , w t m i d v n

Press , after the bookmark key to visit the pinned directory.

You can pin one directory at a time.

3. Filter filtered entries

Filtering is the nnn way to search files in a directory. Did you know it's possible to apply a new filter on already filtered results?

  • Go to a directory
  • Press filter key (/) and type a filter
  • Press Esc or Up or Down (the filter will disappear from the status bar)
  • Press filter key again
  • Type a new filter to find matches in the earlier filtered results

4. Mount and modify archives

nnn provides you an option to mount archives when you press Enter on an archive. Press m to mount the archive and nnn will mount the archive and take you to the mountpoint of the mounted archive.

Add some files in the mounted archive, go back to the nnn config directory (${XDG_CONFIG_HOME:-$HOME/.config}/nnn) and hover on the archive mount point. Press u to unmount the archive and generate a package with the new files. The original package is saved with the extension .orig.

5. Hovered file path in $nnn

nnn exports the hovered file path as $nnn when you press the command prompt or spawn shell shortcuts. You can use the variable to run a command on the hovered file:

ls -l "$nnn"

6. Preview and edit files

You can easily edit and view the changes to Markdown, man pages etc. in nnn. For this you need to use a CLI file opener. You can use plugin nuke, a customizable example opener to specify your preferred apps. To set nuke as the default opener:

export NNN_OPENER=/absolute/path/to/nuke

and start nnn as nnn -c.

The option -c indicates to nnn that the opener is a CLI-only opener (note that nuke can open files in GUI apps as well; please read the documentation in the file).

Now when you press Enter on a Markdown file nuke will try to open it in glow or a man page in man.

To edit the file in $VISUAL (or $EDITOR, or vi), hover on the file and press e.

7. Prompt shortcuts

Even if you compile nnn without libreadline, the native input prompts support several readline-like keys - ^A, ^B, ^D, ^E, ^F, ^K, ^U, ^W.

8. Run custom commands with hotkeys

nnn allows you to run custom commands like plugins. For example, to open a log file in lnav, add a plugin-ish key:command pair in your NNN_PLUG environment variable:

export NNN_PLUG='l:-_lnav $nnn*'

Press ; (select plugin shortcut) followed by l to open a log file in lnav.

You can control several aspects while running commands and plugins (e.g., skip dir refresh after running a plugin, skip user confirmation after running a command) and even run GUI apps as a plugin. Visit plugins for more details.

Note: lnav was taken as an example, you can easily open log files in lnav by editing the customizable sample opener nuke.

9. Select files from anywhere!

Unlike other file managers, nnn allows selection from multiple directories and contexts! You can use the selection in any context as well.

10. Create dirs or files with tree, duplicate anywhere

When you create a new dir/file in nnn (with key n), you can specify a relative path along with parent directories of the new entry. nnn works like mkdir -p in this respect (also for files!).

You can also duplicate a file anywhere using a relative path. To duplicate a file:

  • Press ^R, the rename/duplicate key
  • Skip the rename prompt by pressing Enter
  • At the duplicate prompt specify the relative path to the copy

This is the second part of the power features series (Part 1).

11. Full-featured batch file renamer

Plugin .nmv is a full-featured batch renamer utility that nnn auto-detects and invokes. If plugins are not installed nnn uses the built-in (and feature limited) fallback batch file renaming capability.

12. Auto-synced selection for terminal multiplexers

All instances of nnn write to the same selection file on the disk when a file is selected. The file paths written by the last instance in which files were selected is available to all other instances. So, 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.

13. Open text files detached

It's easy to set up a custom text file opener script for nnn to open text based files in a new tmux split pane or a new terminal tab/window (instructions with sample script).

14. Export file list

Use the shortcut > to export the list of (filtered) entries to a temporary file and edit it in your editor.

There's a plugin treeview to list the files in the current directory along with permissions and size as a tree. File details show the UID and GID of individual files. To list UID and GID of all the files in the directory use plugin uidgid.

15. Enhanced X11 integration

In addition to opening all files with the desktop opener by default in a desktop environment, nnn comes with an additional option -x to show desktop notifications when operations like copy, move or remove complete and to keep selection in sync with the system clipboard.

16. Configurable middle mouse click

If your version of ncurses supports it, the middle mouse click can be configured to emulate any key by defining the config option NNN_MCLICK.

17. Subtree search and open file (or go to directory)

The plugins fzopen and fzcdare handy to fuzzy search and find a file/directory in a subtree and open it or open the containing directory in the current or a different context in nnn.

18. Compile out features

Compiling nnn from source is super-easy because of minimal library dependencies. And we take complete advantage of this! One of the major implementation aspects of nnn is extreme modularity. So you can pick just the pieces you need and make it even leaner and lighter!!! With make variables, you can:

  • compile out libreadline and use in-built input handler (O_NORL=1)
  • compile with PCRE lib to replace POSIX regex (O_PCRE=1)
  • compile out mouse support (O_NOMOUSE=1)
  • compile out locale support (O_NOLOC=1) (risky)
  • compile out native batch renamer (O_NOBATCH=1)

You can also compile nnn statically (O_STATIC=1).

19. Access time and inode change time

In addition to modification time (default), nnn can also order files by access time and inode change time.

20. Trash files

By default nnn deletes files irrecoverably using rm. To trash files instead, install FreeDesktop compliant trash-cli. Then tell nnn to use it:

export NNN_TRASH=1

21. Cool goodies!

If an idle timeout is set and none of the platform-specific terminal lockers are found, nnn invokes cmatrix as the fallback. Try the option -t for this really cool eye candy!

Use option -F to show fortune cookies in the help and settings screen (key ?)!

Clone this wiki locally