vimneovimansi-colorsfzfvim-fzf

How to use ansi colors in fzf --header?


I have try to change the font color in fzf's header.

Here's an example: https://github.com/linrongbin16/fzfx.vim/blob/fa1723e8185e3c2e3d45b6937383ef283c0d3297/autoload/fzfx/vim.vim#L88

But the ansi color code is not working, it just prints:

:: Press [0;31mCTRL-G[0m to fuzzy search

enter image description here

How can I fix it?


Solution

  • You are missing the escape character before the ANSI sequence.

    There are several ways how to represent this character. To type it literally in vim do ctrl+v then Esc in insert mode. In vim that character is displayed as ^[ with special highlighting, so it should eventually look:

    enter image description here

    Alternatively, you are better to fix set_ansi_color():

    function! s:set_ansi_color(content)
        return nr2char(0x1B).s:ansi_colors.red.a:content.s:ansi_colors.clear
    endfunction