I am on neovim with Oni. vim-netranger plugin uses terminal colors in this format to highlight things. It does work in terminal with neovim , but not in a gui app.

I am looking for a way to replace this that will work.

def c256(msg, c, background):
    if background:
        return '[38;5;{};7m{}[0m'.format(c, msg)
        return '[38;5;{}m{}[0m'.format(c, msg)

This string is printed into a line(in a buffer) somehow.



Those are ANSI escape sequences which are commonly used to print colored text in terminal windows. If valid sequences are being inserted into Vim buffers then you'll be happy to know that there's a plugin that will translate to Vim highlighting/colors: AnsiEsc

Here's are basic examples of the concepts...

Using something close to one of your samples this shows what happens on shell command line...

ASCII escape sequence in Bash

Now if we redirect the printf output to a file and open with generic Vim we see...

ASCII escape sequence in Vim

With plugin installed just run command :AnsiEsc and you get...

demo of AnsiEsc plugin


Assuming by text line OP means the command line window (e.g., via echom), use :echohl to set the colors and :echom to print strings.

Note that echohl uses the available highlight groups; you may want to use execute and highlightto create your own from function arguments if custom highlights are needed. Otherwise, just lean on the provided groups and trust the colorscheme.

For a buffer you need to use custom syntax commands, or borrow an existing syntax.

See the relevant docs.

  • Thank, but it is just a buffer. Not the command line window. – eyal karni Jun 10 '19 at 21:35

I ask it also here


and what he wrote is:

I now see that this is because I didn't set the highlit color for gui in the syntax file. The line should be modified to something like:

 'hi NETRhi'.c.' ctermfg='.c.' ctermbg=None guifg=#rrggbb guibg =None'

It is working now.

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.