Search code examples
windowscommand-promptsyntax-highlightingnano

Nano syntax color highlighting in windows


How do I get this to work, I did add the color syntax highlighting configuration in nano.rc and .nanorc, but nothing happen.


Solution

  • The previous answer is outdated and also wrong.

    Most of the problem with the coloring is due to the fact that the native build windows version doesn't support windows paths, as it's using GNU's glob(). So you need to use forward POSIX style paths in your syntax include statement in the .nanorc file.

    Here is the entire install procedure:

    1. Download the latest Nano build from here OR here.

    2. Download the latest syntax highlighter files *.nanorc from here

    3. Chose an installation location. For example in C:\nano\.

    4. Extract the contents into that directory and move it around so that you have:

    C:\nano\bin\       # For the nano.exe
    C:\nano\nanorc\    # For all the *.nanorc files
    C:\nano\doc\       # For the documentation files
    
    1. Put the .nanorc into your home directory in: C:\Users\<username>\.nanorc.

    2. Add the nano file paths to your System Path:

    # To set and update the Windows (System) "Path" in Powershell, use:
    [System.Environment]::SetEnvironmentVariable("PATH", $Env:Path + ";C:\nano\bin", "Machine")
    
    1. Reboot, restart explorer, or install refreshenv from choco.

    2. Optional: Run nano once, to ensure that a filepos_history file is created.

    3. You probably want to be able to run Nano with both normal or Administrator privileges, but not having to keep track of more edit locations and 2nd config files. To do this, you need to symlink your own versions of the nano config and history setting files, to the admin versions.

    # Link last cursor position files:
    New-Item -ItemType SymbolicLink -Path "C:\ProgramData\.local\share\nano\filepos_history" -Target  "C:\Users\<username>\.local\share\nano\filepos_history" -Force
    
    # Link .nanorc files:
    New-Item -ItemType SymbolicLink -Path "C:\ProgramData\.nanorc" -Target  "C:\Users\<username>\.nanorc" -Force
    
    1. IMPORTANT!
      Edit your .nanorc to include the correct POSIX paths to all your *.nanorc files.
    # Why not use nano to edit your .nanorc
    cd ~
    nano .nanorc
    
    # Add the following line(s):
    #include "C:\nano\nanorc\*.nanorc"     # Windows paths does NOT work!
    include "/nano/nanorc/*.nanorc"        # This works!
    

    Enjoy!