kevinhwang91 / nvim-ufo

Not UFO in the sky, but an ultra fold in Neovim.
BSD 3-Clause "New" or "Revised" License
2.18k stars 38 forks source link

Folds not being highlighted #106

Closed hanzokumori closed 1 year ago

hanzokumori commented 1 year ago

Neovim version (nvim -v | head -n1)

NVIM v0.8.2

Operating system/version

Fedora 37

How to reproduce the issue

I think this might be something wrong with my config instead since no one else has this issue.

This is my complete config file. Copy pasted from the readme. Not exactly sure what's the issue but the folds are not being highlighted and there seem to be numbers at foldcolumn?

I'm using catppuccin theme with transparent background. Tried turning that off but it still didn't appear.

vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
vim.o.foldcolumn = '1'
vim.o.foldlevel = 99 -- Using ufo provider need a large value, feel free to decrease the value
vim.o.foldlevelstart = 99
vim.o.foldenable = true

vim.keymap.set('n', 'zR', require('ufo').openAllFolds)
vim.keymap.set('n', 'zM', require('ufo').closeAllFolds)

local handler = function(virtText, lnum, endLnum, width, truncate)
  local newVirtText = {}
  local suffix = ('  %d '):format(endLnum - lnum)
  local sufWidth = vim.fn.strdisplaywidth(suffix)
  local targetWidth = width - sufWidth
  local curWidth = 0
  for _, chunk in ipairs(virtText) do
    local chunkText = chunk[1]
    local chunkWidth = vim.fn.strdisplaywidth(chunkText)
    if targetWidth > curWidth + chunkWidth then
      table.insert(newVirtText, chunk)
    else
      chunkText = truncate(chunkText, targetWidth - curWidth)
      local hlGroup = chunk[2]
      table.insert(newVirtText, { chunkText, hlGroup })
      chunkWidth = vim.fn.strdisplaywidth(chunkText)
      -- str width returned from truncate() may less than 2nd argument, need padding
      if curWidth + chunkWidth < targetWidth then
        suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth)
      end
      break
    end
    curWidth = curWidth + chunkWidth
  end
  table.insert(newVirtText, { suffix, 'MoreMsg' })
  return newVirtText
end

-- global handler
-- `handler` is the 2nd parameter of `setFoldVirtTextHandler`,
-- check out `./lua/ufo.lua` and search `setFoldVirtTextHandler` for detail.
require('ufo').setup({
  fold_virt_text_handler = handler
})

Expected behavior

https://user-images.githubusercontent.com/17562139/174121926-e90a962d-9fc9-428a-bd53-274ed392c68d.png

Actual behavior

2023-01-29T23:07:39,252429611+08:00

Highlight doesn't show and there seems to be some numbers by the side

kevinhwang91 commented 1 year ago

hi Folded guibg=yellow ctermbg=yellow

hanzokumori commented 1 year ago

ahh. I didn't know the highlight colors have to be set. Thank you so much!

Is there a way to remove the numbers at the numberline but still keep the arrows? I like it cleaner that way.

I've tried vim.o.foldcolumn = '0' but that just removes everything. Played around with vim.o.fillchars as well but can't seem to make it work

kevinhwang91 commented 1 year ago

https://github.com/kevinhwang91/nvim-ufo/issues/4