I have seen some screenshots where ranger uses syntax-highlighting in its preview window. So I was wondering how to enable this feature and found out that I need the scope.sh file in the directory /home/user/.config/ranger/scop.sh, which will be generated with the command $ ranger --copy-config=scope. After generating it however the preview window completely disappears, although I inserted set use_preview_script true in rc.config.

Q: Does someone know how to enable syntax-highlighting (especially for C/C++) in the ranger preview window?

2 Answers 2

$ sudo apt install highlight

then reopen ranger.

  • 3
    sudo pacman -S highlight worked on Arch for me.
    – Kevin
    Mar 18, 2019 at 10:17

Ranger supports highlight, see http://www.andre-simon.de/doku/highlight/en/highlight.php for details

Install on macOS by running brew install highlight. The list of available themes can be seen under: highlight/<highlight_version>/share/highlight/themes e.g.:

/usr/local/Cellar/highlight/3.54/share/highlight/themes$ ls 

base16             clarity.theme              easter.theme             edit-vim.theme    molokai.theme       relaxedgreen.theme
acid.theme         dante.theme                edit-anjuta.theme        edit-xcode.theme  moria.theme         rootwater.theme
aiseered.theme     darkblue.theme             edit-bbedit.theme        ekvoli.theme      navajo-night.theme  seashell.theme
andes.theme        darkbone.theme             edit-eclipse.theme       fine_blue.theme   navy.theme          solarized-dark.theme
anotherdark.theme  darkness.theme             edit-emacs.theme         freya.theme       neon.theme          solarized-light.theme
autumn.theme       darkplus.theme             edit-fasm.theme          fruit.theme       night.theme         sourceforge.theme
baycomb.theme      darkslategray.theme        edit-flashdevelop.theme  github.theme      nightshimmer.theme  tabula.theme
bclear.theme       darkspectrum.theme         edit-gedit.theme         golden.theme      nuvola.theme        tcsoft.theme
biogoo.theme       denim.theme                edit-godot.theme         greenlcd.theme    olive.theme         the.theme
bipolar.theme      duotone-dark-earth.theme   edit-jedit.theme         kellys.theme      orion.theme         vampire.theme
blacknblue.theme   duotone-dark-forest.theme  edit-kwrite.theme        leo.theme         oxygenated.theme    whitengrey.theme
bluegreen.theme    duotone-dark-sea.theme     edit-matlab.theme        lucretia.theme    pablo.theme         xoria256.theme
breeze.theme       duotone-dark-sky.theme     edit-msvs2008.theme      manxome.theme     peaksea.theme       zellner.theme
bright.theme       duotone-dark-space.theme   edit-nedit.theme         maroloccio.theme  print.theme         zenburn.theme
camo.theme         dusk.theme                 edit-purebasic.theme     matrix.theme      rand01.theme        zmrok.theme
candy.theme        earendel.theme             edit-vim-dark.theme      moe.theme         rdark.theme

Ranger configures highlighting in scope.sh. To use a specific theme, the HIGHLIGHT_STYLE variable should be set, for example: export HIGHLIGHT_STYLE=clarity

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.