nvim-tree / nvim-web-devicons

lua `fork` of vim-web-devicons for neovim
MIT License
2.09k stars 184 forks source link

Add ambiwidth option #116

Open sei40kr opened 2 years ago

sei40kr commented 2 years ago

I want an option to tell Neovim what to do with East Asian Width Class Ambiguous.

Neovim already has ambiwidth option but it's unstable since it applies to all the characters in Neovim.

                        *'ambiwidth'* *'ambw'*
'ambiwidth' 'ambw'  string (default: "single")
            global
    Tells Vim what to do with characters with East Asian Width Class
    Ambiguous (such as Euro, Registered Sign, Copyright Sign, Greek
    letters, Cyrillic letters).

    There are currently two possible values:
    "single":   Use the same width as characters in US-ASCII.  This is
            expected by most users.
    "double":   Use twice the width of ASCII characters.
                            *E834* *E835*
    The value "double" cannot be used if 'listchars' or 'fillchars'
    contains a character that would be double width.

    There are a number of CJK fonts for which the width of glyphs for
    those characters are solely based on how many octets they take in
    legacy/traditional CJK encodings.  In those encodings, Euro,
    Registered sign, Greek/Cyrillic letters are represented by two octets,
    therefore those fonts have "wide" glyphs for them.  This is also
    true of some line drawing characters used to make tables in text
    file.  Therefore, when a CJK font is used for GUI Vim or
    Vim is running inside a terminal (emulators) that uses a CJK font
    (or Vim is run inside an xterm invoked with "-cjkwidth" option.),
    this option should be set to "double" to match the width perceived
    by Vim with the width of glyphs in the font.  Perhaps it also has
    to be set to "double" under CJK MS-Windows when the system locale is
    set to one of CJK locales.  See Unicode Standard Annex #11
    (http://www.unicode.org/reports/tr11).

I've already implemented this in my dotfiles, so I want to port this to upstream. ~https://github.com/sei40kr/dotfiles/blob/master/config/neovim/lua/config/plugins/nvim-web-devicons.lua#L14-L18~ https://github.com/sei40kr/yonvim/blob/main/lua/yvim/plugin/web-devicons.lua

kyazdani42 commented 2 years ago

i'm not sure this should be implemented here, maybe plugin authors using this could manage it themselves ? So just a documentation improvement would be needed ?

sei40kr commented 2 years ago

@kyazdani42 Sorry for my late repsonse.

I think it should be implemented here.

I noticed Vim already have setcellwidths() to set the cell widths of specific unicode characters. And recently same feature has been merged to Neovim upstream in neovim/neovim#19686.

So in the near future, we can provide the default cell width for each icon easily using setcellwidths(), like vim-ambiwidth does.