5

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

not2qubit
  • 14,531
  • 8
  • 95
  • 135
syarul
  • 2,161
  • 2
  • 20
  • 22
  • [The `nano` FAQ](http://www.nano-editor.org/dist/v2.2/faq.html#3.9) says to put your `.nanorc` in your Windows `HOME` directory. You may need to set the `HOME` environment variable for this to work on Windows. – stiemannkj1 Sep 12 '15 at 12:03

2 Answers2

4

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!

not2qubit
  • 14,531
  • 8
  • 95
  • 135
  • 1
    Thank you. I installed it through Chocolatey. Copying .nanorc to my home directory and replacing the backslashes with forward slashes did it for me. – ecv Mar 23 '23 at 12:15
2

Set an environment variable named HOME to your user directory (the one that cd ~ places you in eg. C:\users\yourname).

Then copy the nano.rc file from the installation directory to your home directory.

NOTE: it's nano.rc not .nanorc like it is in Linux -- the latter will not work in the Windows version.

Then uncomment the settings you want in the nano.rc file. The current Windows port does not have mouse support so do not enable that feature.

Make sure to save the nano.rc with unix line endings or it will not work.

Go grab syntax highlighting from somewhere. Example: https://github.com/scopatz/nanorc

To install from the repo above, open the folder where you extracted the nano application files to and type this:

mkdir syntax
cd syntax
git clone https://github.com/scopatz/nanorc.git .

You may want to adjust the nanorc.nanorc file from the repo above to include .rc if you want syntax highlighting on the main nano.rc file. To do this, adjust the line:

syntax "Nanorc" "\.?nanorc$"

To this:

syntax "Nanorc" "\.(nano)rc$"

Obviously do not use the installation shell script or the .nanorc from the repo above since they are specific to Linux.

Make sure you point to the syntax files using traditional Windows file paths not the *nix ones (provided by default).

Finally, add the directory where you unzipped nano.exe and accompanying files to in your PATH environment variable so you can just type nano in PowerShell or cmd.exe

Graeme Wicksted
  • 1,770
  • 1
  • 18
  • 21
  • I think I'm following your instructions but am coming up without the config being read. I downloaded a windows nano.rc file, set %HOME% to equal the dir of that file, and ran nano from within that same batch script that sets %HOME%, but no luck. – Mark Deven Oct 12 '19 at 22:49
  • Try setting `%HOME%` to your user's home directory in Windows. This is typically `C:\Users\yourusername` - perhaps this step is no longer required? Then place the `nano.rc` file in that directory and see if it works. – Graeme Wicksted Oct 18 '19 at 18:34
  • Tried that as well, no change. – Mark Deven Oct 25 '19 at 02:26
  • i managed to get it to fetch the nano.rc in the Users Home by setting the "HOME" path in the system. ok. But when i inlude the path to the .nanorc syntax highlighting using inlucde "\cygdrive\c\Users\my_username\.nanorc\javascript.nanorc" i get Error in "path" on line 2: Command "comment" not understood Error in "path" on line 6: Bad regex "[...]": parentheses not balanced I installed nano using choco. and it works fine otherwise. seems the .nanorc files that are used in linux are not working with the windows nano? – AndiAna Apr 13 '20 at 06:52