0

Using vim or nvim, when I open a new vim terminal digraphs display correctly. See below:

enter image description here

However, whenever I change colorscheme (any, it is not specific to a particular colorscheme) - then the digraphs appear highlighted. The highlighting remains even when switching back to the original colorscheme. This happens with any digraph, not just the one shown in this question. See below:

enter image description here

Cannot find a way to remove that highlighting, or prevent it happening in the first place. Have tried commands like :highlight nonascii none but had no luck. Any help / suggestions much appreciated.

arcseldon
  • 35,523
  • 17
  • 121
  • 125

1 Answers1

0

Most/Some of the colorschemes aren't really made for hotswap. It seems to be a rather common problem with solarized f.e.

There is a plugin which handles a change cleanly: https://github.com/xolox/vim-colorscheme-switcher (I haven't tested it).

And I copied a bunch of functions for that somewhere which works arround the problems most of the time. I don't know where I got it from, but I want to be clear, it is not my work!

function! s:Find_links() " {{{1
  " Find and remember links between highlighting groups.
  redir => listing
  try
    silent highlight
  finally
    redir END
  endtry
  for line in split(listing, "\n")
    let tokens = split(line)
    " We're looking for lines like "String xxx links to Constant" in the
    " output of the :highlight command.
    if len(tokens) == 5 && tokens[1] == 'xxx' && tokens[2] == 'links' && tokens[3] == 'to'
      let fromgroup = tokens[0]
      let togroup = tokens[4]
      let s:known_links[fromgroup] = togroup
    endif
  endfor
endfunction

function! s:Restore_links() " {{{1
  " Restore broken links between highlighting groups.
  redir => listing
  try
    silent highlight
  finally
    redir END
  endtry
  let num_restored = 0
  for line in split(listing, "\n")
    let tokens = split(line)
    " We're looking for lines like "String xxx cleared" in the
    " output of the :highlight command.
    if len(tokens) == 3 && tokens[1] == 'xxx' && tokens[2] == 'cleared'
      let fromgroup = tokens[0]
      let togroup = get(s:known_links, fromgroup, '')
      if !empty(togroup)
        execute 'hi link' fromgroup togroup
        let num_restored += 1
      endif
    endif
  endfor
endfunction

function! s:AccurateColorscheme(colo_name)
  call <SID>Find_links()
  exec "colorscheme " a:colo_name
  call <SID>Restore_links()
endfunction

command! -nargs=1 -complete=color MyColorscheme call <SID>AccurateColorscheme(<q-args>)
Doktor OSwaldo
  • 5,732
  • 20
  • 41