Does nano select the wrong syntax highlighter? But how to know which?
Tuesday, December 16, 2025
Ever have a problem where you open a file, say httpd-vhosts.conf, and it is highlighted with the wrong syntax highlighter? Unlike vim, nano won’t tell you which highlighter it is using. You could, of course, disable each one-by-one until you get the correct highlighting or maybe this little bash script will come in handy:
# for file in /usr/local/share/nano/*.nanorc; do
syntax_line=$(grep '^syntax ' "$file" | head -1)
if [ -n "$syntax_line" ]; then
echo "$syntax_line" | grep -oE '"[^"]+"' | while read -r quoted_pattern; do
pattern=$(echo "$quoted_pattern" | tr -d '"')
if echo "httpd-vhosts.conf" | grep -qE "$pattern" 2>/dev/null; then
echo "MATCH: $file"
echo " Pattern: $pattern"
echo " Full syntax line: $syntax_line"
echo
fi
done
fi
done
Modify the if echo "httpd-vhosts.conf" line as appropriate to your use case. It should return something like:
MATCH: /usr/local/share/nano/apacheconf.nanorc Pattern: httpd\.conf|httpd-vhosts\.conf|mime\.types|vhosts\.d\\*|\.htaccess|httpd-.*\.conf$ Full syntax line: syntax "Apacheconf" "httpd\.conf|httpd-vhosts\.conf|mime\.types|vhosts\.d\\*|\.htaccess|httpd-.*\.conf$" MATCH: /usr/local/share/nano/etc-hosts.nanorc Pattern: hosts Full syntax line: syntax "/etc/hosts" "hosts"
Yep, that’ll do it. Fixed.
-
Recent Posts
- Does nano select the wrong syntax highlighter? But how to know which? 2025 December 16
- Serial dependencies are a catastrophe already starting to happen 2025 November 19
- Cleaning up poor quality laser scans with Meshlab 2025 September 12
- Disappearing checks in WordPress checkboxes 2025 July 29
- Apropos of nothing in particular…. 2025 March 26
- Treegraph.sh a tool for generating pretty file structure graphs 2025 February 28
- FINAL System shutdown after 16 years 2025 February 12
- Adding a feature to MediaWiki WikiEditor formatting 2025 January 18
- Technology democratizes nuclear-grade munitions 2025 January 10
- Optane, a modern technology tragedy (plus FreeBSD nvmecontrol) 2025 January 05
- Categories
- Links
- Search
- Archives
- Post History
December 2025 M T W T F S S 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31