0

While using nnn, I need to edit a file that requires sudo privileges.

I love that I'm able to navigate quickly to the file I want to edit using nnn, and how it immediately opens the file in my editor. Yet upon making modifications, I cannot save the file without root privileges.

This really breaks the flow of what I like about nnn. Is there a quick way I can launch the editor from a file in nnn (with sudo)?

Lonnie Best
  • 4,895
  • 6
  • 27
  • 42

1 Answers1

1

nnn will use whatever editor you have defined in the environment variable VISUAL as the editor when editing a file by pressing e in the browser, or it will pick some system default editor.

This means that you may set VISUAL to e.g. sudo vi before invoking nnn:

VISUAL='sudo vi' nnn

Note that this globally changes the behaviour of the e action in the browser.

The other way to do this is to open the file using o from the browser. nnn will then ask you what to open the file with, and you may, for example, use sudoedit or sudo vi etc. It will then ask you whether the program you are opening uses a command line or a graphical interface. Then it will open the file in the editor appropriately.

Kusalananda
  • 320,670
  • 36
  • 633
  • 936