Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I make it look equal to its configuration #4

Closed
CRAG666 opened this issue Jun 16, 2022 · 62 comments
Closed

How can I make it look equal to its configuration #4

CRAG666 opened this issue Jun 16, 2022 · 62 comments

Comments

@CRAG666
Copy link

CRAG666 commented Jun 16, 2022

Currently my line looks like this and I would like it to be seen as yours
screen-1655388054

@kevinhwang91
Copy link
Owner

kevinhwang91 commented Jun 16, 2022

  1. vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
  2. vim.o.foldcolumn = '1'
  3. need this PR feat(folds): add 'foldoptions' option neovim/neovim#17446 , this PR only changes a few lines, but you must compile the code by yourself.

I will add the note under demo later.

@kevinhwang91
Copy link
Owner

Actually I haven't used that PR, I hacked myself a long ago, and found that PR recently.

diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 2ee7cd44f..8982bd2ee 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -1931,12 +1931,8 @@ static size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_
     if (foldinfo.fi_lnum == lnum
         && first_level + i >= foldinfo.fi_low_level) {
       symbol = wp->w_p_fcs_chars.foldopen;
-    } else if (first_level == 1) {
-      symbol = wp->w_p_fcs_chars.foldsep;
-    } else if (first_level + i <= 9) {
-      symbol = '0' + first_level + i;
     } else {
-      symbol = '>';
+      symbol = wp->w_p_fcs_chars.foldsep;
     }
 
     len = utf_char2bytes(symbol, (char *)&p[char_counter]);

@kevinhwang91 kevinhwang91 reopened this Jun 16, 2022
@CRAG666
Copy link
Author

CRAG666 commented Jun 16, 2022

Tanks

@hisamafahri
Copy link

hisamafahri commented Jun 19, 2022

@CRAG666 @kevinhwang91 How to remove the number '2' sign in the image above?

@kevinhwang91
Copy link
Owner

For now, must compile Neovim source code.

@bandithijo
Copy link

bandithijo commented Jun 19, 2022

How to remove the number '2' sign in the image above?

@hisamafahri
You need to modify the file src/nvim/screen.c in source code with the diff sample above #4 (comment) and recompile.
The indent level number indicator will be gone.

@data-stepper
Copy link

I have found a temporary workaround for this issue, if you set foldcolumn='5' (or some other higher number than 1), it will not show the digits for lower level folds.

Only this way you have to live with the bigger column on the left side, which I actually kind of like since it also shows you the fold levels by shifting the little markers correctly.

@ruanyouxing
Copy link

What font have you used?
The icon is just too small to clickable
image

@kevinhwang91
Copy link
Owner

What font have you used? The icon is just too small to clickable image

cat alacritty.yml

font:
  normal:
    family: Hack Nerd Font

Search chevron in https://www.nerdfonts.com/cheat-sheet

@ruanyouxing
Copy link

thanks a lot

@p00f
Copy link

p00f commented Jul 8, 2022

for foldopen and for foldclose are unicode (work without nerd fonts)

@cathaysia
Copy link

How do I change the color of filechars?

@kevinhwang91
Copy link
Owner

How do I change the color of filechars?

h FoldColumn

@kevinhwang91
Copy link
Owner

I am trying my best to imp #24 which I think is better than VSCode UI. Suggestions are welcome.

@diego-treitos
Copy link

diego-treitos commented Aug 7, 2022

if you set foldnestmax to a number equal or lower than the foldcolumn (i.e. both to 2) it won't show the ugly numbers

@twnaing
Copy link

twnaing commented Aug 12, 2022

I thought the number displayed is a bug. After reading this, I understand it is a feature.

@diego-treitos
Copy link

diego-treitos commented Aug 12, 2022

Yes, it is a feature. However, at least for me, the problem is that there isn't seem to be a way to configure the fold columns to resize dynamically as they are needed. You either have:

  • As many columns as possible folds in the file: This means that in a file with 7 levels of folds, when you open it it will show 7 fold columns despite only having symbols in the first column (folds are closed).

  • A fixed number of columns: This means that the numbers in the fold columns will appear unless you also limit the number of folds in the file to the number of fold columns.

If I am wrong about this please anybody let me know :)

jdhao added a commit to jdhao/nvim-config that referenced this issue Aug 16, 2022
Currently there are display issues that needs to be addressed in nvim
core, see kevinhwang91/nvim-ufo#4 .
@kevinhwang91 kevinhwang91 pinned this issue Sep 4, 2022
@alex-popov-tech
Copy link

@kevinhwang91 hey! if i don't want to recompile nvim, can i disable foldcolumn until PR is merged? i tried to set it to 0, and on starting screen it is 0, but when entering some file buffer it resets to 1 with those fold levels in digits :(

@kevinhwang91
Copy link
Owner

@kevinhwang91 hey! if i don't want to recompile nvim, can i disable foldcolumn until PR is merged? i tried to set it to 0, and on starting screen it is 0, but when entering some file buffer it resets to 1 with those fold levels in digits :(

Sure. 0 is recommended if don't compile nvim. Write down o.foldcolumn = '0' in init.lua and check out which script changes your foldcolumn.

@alex-popov-tech
Copy link

i did that, tho i thought it was your plugin who does this :D even tho i didn't find such code in repo...okay, thank you, i will try to use some rg in plugins dir to find who is changing that, thank you!

@WhiteBlackGoose
Copy link

Update of the patch from above:

From b9de2d3eddac3cc9bd2c03f8adaca13b0da14fef Mon Sep 17 00:00:00 2001
From: WhiteBlackGoose <wbg@angouri.org>
Date: Sat, 3 Dec 2022 21:47:29 +0300
Subject: [PATCH] folding UI made nicer

---
 src/nvim/screen.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/src/nvim/screen.c b/src/nvim/screen.c
index 865520657..52d619fff 100644
--- a/src/nvim/screen.c
+++ b/src/nvim/screen.c
@@ -215,12 +215,8 @@ size_t fill_foldcolumn(char_u *p, win_T *wp, foldinfo_T foldinfo, linenr_T lnum)
     if (foldinfo.fi_lnum == lnum
         && first_level + i >= foldinfo.fi_low_level) {
       symbol = wp->w_p_fcs_chars.foldopen;
-    } else if (first_level == 1) {
-      symbol = wp->w_p_fcs_chars.foldsep;
-    } else if (first_level + i <= 9) {
-      symbol = '0' + first_level + i;
     } else {
-      symbol = '>';
+      symbol = wp->w_p_fcs_chars.foldsep;
     }
 
     len = utf_char2bytes(symbol, (char *)&p[char_counter]);
-- 
2.38.1

FWIW I decided to maintain my fork of neovim. If I'm not lazy, I will make it autorelease

@Racle
Copy link

Racle commented Feb 17, 2023

@rsdubtso I've been using indent-blankline.nvim with folliwing config:

require("indent_blankline").setup {
  char = "",
  buftype_exclude = {"terminal"},
  show_trailing_blankline_indent = false,
  show_current_context = true,
  filetype_exclude = {"help", "terminal"},
  -- default : {'class', 'function', 'method'}
  context_patterns = {
    "class",
    "function",
    "method",
    "^if",
    "^while",
    "^for",
    "^object",
    "^table",
    "^type",
    "^import",
    "block",
    "arguments"
  }
  -- disabled now for performance hit.
  -- use_treesitter = true
}

@rockyzhang24
Copy link

@rsdubtso That's implemented by other plugins, not nvim-ufo. Please check indentLine, or indent-blankline.

@rsdubtso
Copy link

D'oh! Thanks a lot!. Hope this discussion is at least somewhat useful for future readers...

@AGou-ops
Copy link

AGou-ops commented Apr 7, 2023

neovim v0.9.0 src/nvim/screen.c --> src/nvim/drawline.c.

About line 421.

 418   for (i = 0; i < MIN(fdc, level); i++) {
 419     if (foldinfo.fi_lnum == lnum
 420         && first_level + i >= foldinfo.fi_low_level) {
 421       symbol = wp->w_p_fcs_chars.foldopen;
 422     } else if (first_level == 1) {
 423       symbol = wp->w_p_fcs_chars.foldsep;
 424     } else if (first_level + i <= 9) {
 425       symbol = '0' + first_level + i;
 426     } else {
 427       symbol = '>';
 428     }

@pedropombeiro
Copy link

@kevinhwang91 Now that Neovim 0.9.0 is out, what is the right way to enable this look?

@rockyzhang24
Copy link

rockyzhang24 commented Apr 8, 2023

@pedropombeiro Now the plugin statuscol.nvim is stable enough and is worth a trying. The alternative approach is to change the code in screen.c (that was refactored and renamed to drawline.c) directly and build neovim by yourself.

@jellydn
Copy link

jellydn commented Apr 18, 2023

Here is my entire UFO + Folding preview config, just in case someone needs this.

  1. Setup folding option
-- UFO folding
vim.o.foldcolumn = "1" -- '0' is not bad
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.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
  1. Install the plugin with lazy.nvim
return {
  -- UFO folding
  {
    "kevinhwang91/nvim-ufo",
    dependencies = {
      "kevinhwang91/promise-async",
      {
        "luukvbaal/statuscol.nvim",
        config = function()
          local builtin = require("statuscol.builtin")
          require("statuscol").setup({
            relculright = true,
            segments = {
              { text = { builtin.foldfunc }, click = "v:lua.ScFa" },
              { text = { "%s" }, click = "v:lua.ScSa" },
              { text = { builtin.lnumfunc, " " }, click = "v:lua.ScLa" },
            },
          })
        end,
      },
    },
    event = "BufReadPost",
    opts = {
      provider_selector = function()
        return { "treesitter", "indent" }
      end,
    },

    init = function()
      vim.keymap.set("n", "zR", function()
        require("ufo").openAllFolds()
      end)
      vim.keymap.set("n", "zM", function()
        require("ufo").closeAllFolds()
      end)
    end,
  },
  -- Folding preview, by default h and l keys are used.
  -- On first press of h key, when cursor is on a closed fold, the preview will be shown.
  -- On second press the preview will be closed and fold will be opened.
  -- When preview is opened, the l key will close it and open fold. In all other cases these keys will work as usual.
  { "anuvyklack/fold-preview.nvim", dependencies = "anuvyklack/keymap-amend.nvim", config = true },
}

Demo:
https://gyazo.com/f5d5019313deed7c01faed43aa6e064f.gif

@awerebea
Copy link

Let me join the party and share my config with one small extra "feature" of displaying the number of hidden rows near the colorcolumn or window edge (whichever is smaller).

return {
  "kevinhwang91/nvim-ufo",
  dependencies = "kevinhwang91/promise-async",
  event = "VeryLazy",
  opts = {
    -- INFO: Uncomment to use treeitter as fold provider, otherwise nvim lsp is used
    -- provider_selector = function(bufnr, filetype, buftype)
    --   return { "treesitter", "indent" }
    -- end,
    open_fold_hl_timeout = 400,
    close_fold_kinds = { "imports", "comment" },
    preview = {
      win_config = {
        border = { "", "", "", "", "", "", "", "" },
        -- winhighlight = "Normal:Folded",
        winblend = 0,
      },
      mappings = {
        scrollU = "<C-u>",
        scrollD = "<C-d>",
        jumpTop = "[",
        jumpBot = "]",
      },
    },
  },
  init = function()
    vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
    vim.o.foldcolumn = "1" -- '0' is not bad
    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
  end,
  config = function(_, opts)
    local handler = function(virtText, lnum, endLnum, width, truncate)
      local newVirtText = {}
      local totalLines = vim.api.nvim_buf_line_count(0)
      local foldedLines = endLnum - lnum
      local suffix = ("  %d %d%%"):format(foldedLines, foldedLines / totalLines * 100)
      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
      local rAlignAppndx =
        math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)
      suffix = (" "):rep(rAlignAppndx) .. suffix
      table.insert(newVirtText, { suffix, "MoreMsg" })
      return newVirtText
    end
    opts["fold_virt_text_handler"] = handler
    require("ufo").setup(opts)
    vim.keymap.set("n", "zR", require("ufo").openAllFolds)
    vim.keymap.set("n", "zM", require("ufo").closeAllFolds)
    vim.keymap.set("n", "zr", require("ufo").openFoldsExceptKinds)
    vim.keymap.set("n", "K", function()
      local winid = require("ufo").peekFoldedLinesUnderCursor()
      if not winid then
        -- vim.lsp.buf.hover()
        vim.cmd [[ Lspsaga hover_doc ]]
      end
    end)
  end,
}

Examples:
2023-04-19_145514
2023-04-19_145601

@sudoCompetence
Copy link

@awerebea thats just amazing.

However the arrow and percentage for me appear where the code ends not and the end of the window like yours. How did you modify the 'hidden' data to be at the end of the window?

@awerebea
Copy link

awerebea commented Apr 23, 2023

Hey @sudoCompetence! Glad you like it.

How did you modify... ?

Well, I just took the example from Customize fold text and modified it to take into account the textwidth property, so in my implementation, the position actually depends on texdtwidth but not on colorcolumn, sorry for the confusion.

This is the diff of the changes made:
image

@MariaSolOs
Copy link

MariaSolOs commented Jul 6, 2023

Idk if it's just me, but on nightly I had to change my statuscol config to include disable_ft = { 'trouble' }, else Neovim crashes with a 134 exit code. Curious to know if anyone else experienced something similar.

@nick22985
Copy link

@awerebea thats just amazing.

However the arrow and percentage for me appear where the code ends not and the end of the window like yours. How did you modify the 'hidden' data to be at the end of the window?

Sorry for commenting on this again but also wanted to make it so that the fold was all the way to the right so for those in the future that want this here. You can do it by doing the below:
#4 (comment)

replace this line:

local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)

with

local rAlignAppndx = math.max(math.min(vim.api.nvim_win_get_width(0), width - 1) - curWidth - sufWidth, 0)

This will put the fold text as far width-wise as your buffer is

Example:
28cf1c538b6970e74ebc76a3de326c52

@awerebea
Copy link

Hi @nick22985,
Well, please feel free to change this snippet this way if you prefer this implementation. 😉
But for me personally, my original way looks better.

The proposed change only affects the display in a wide window, but I'm just used to limiting the width of the text in the window (99 characters for the Lua file type in this example). So it doesn't make much sense for me to place the fold text as far in width as the window of my current buffer.

I set the colorcolumn value equal to +1 for clarity in the following screenshots.
wide window:
proposed change
ufo_0
current
ufo_1
tight window:
ufo_2
really long line with fold:
ufo_3

Again, it's just a matter of taste. In my opinion, all these cases are better covered by my current implementation, but it's obviously up to you to decide which way to use for yourself.

Thank you for your participation!

@gelocraft
Copy link

I have this minimal config for nvim-ufo and it looks amazing to me.
Screenshot from 2024-07-20 at 21:55:13

Additional - adding vim.o.foldcolumn = 'auto:9' will remove the annoying random number on foldcolumn and also adjust the foldcolumn size/width accordingly. Just simply add this on your config.

vim.o.foldcolumn = 'auto:9'

jdhao added a commit to jdhao/nvim-config that referenced this issue Aug 4, 2024
The settings are copied from kevinhwang91/nvim-ufo#4 (comment),
with some modification.
jdhao added a commit to jdhao/nvim-config that referenced this issue Aug 4, 2024
The settings are copied from kevinhwang91/nvim-ufo#4 (comment),
with some modification.
MstMoonshine pushed a commit to MstMoonshine/nvim-config that referenced this issue Aug 10, 2024
The settings are copied from kevinhwang91/nvim-ufo#4 (comment),
with some modification.
@flarocca
Copy link

flarocca commented Dec 6, 2024

Hello folks! I know this issue has been closed, however, I got into an issue that feels as though it is the same issue.
I can't get rid of the ugly numbers when the fold level exceeds 9 as can be seen in the image.

image

Apparently, setting vim.o.foldcolumn = "auto:9" solves the problem, which is true until the fold level is bigger than 9. At that point is when the ugly numbers show up again.
Settging the foldcolumn value to something bigger than 9 breaks the plug in with the following error:

Error detected while processing /Users/flr/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /Users/flr/.config/nvim/lua/options.lua:52: E474: Invalid argument
stack traceback:
        [C]: in function '__newindex'
        /Users/flr/.config/nvim/lua/options.lua:52: in main chunk -- this is the exact line where I set up auto:10
        [C]: in function 'require'
        /Users/flr/.config/nvim/init.lua:32: in main chunk
Press ENTER or type command to continue

This the current options I am using:

vim.o.fillchars = [[eob: ,fold: ,foldopen:▾,foldsep: ,foldclose:▸]]
vim.o.foldcolumn = "auto:10" -- 10 breaks the plugin, 9 works with the issue mentioned before
vim.o.foldnestmax = 1
vim.o.foldlevel = 99999999 -- Bigger than this also breaks the plugin
vim.o.foldlevelstart = 99999999
vim.o.foldenable = true

vim.o.scrolloff = 5
vim.o.sidescrolloff = 5

-- Redrawing and cursor enhancements
vim.o.lazyredraw = false
vim.o.cursorline = true
vim.o.cursorcolumn = true
vim.o.cursorlineopt = "number,line"

And this is the plugin setup

return {
    "kevinhwang91/nvim-ufo",
    dependencies = "kevinhwang91/promise-async",
    event = "VeryLazy",
    opts = {
        open_fold_hl_timeout = 400,
        preview = {
            win_config = {
                border = { "", "─", "", "", "", "─", "", "" },
                winblend = 0,
            },
            mappings = {
                scrollU = "<C-u>",
                scrollD = "<C-d>",
                jumpTop = "[",
                jumpBot = "]",
            },
        },
    },
    config = function(_, opts)
        local handler = function(virtText, lnum, endLnum, width, truncate)
            local newVirtText = {}
            local totalLines = vim.api.nvim_buf_line_count(0)
            local foldedLines = endLnum - lnum
            local suffix = ("  %d %d%%"):format(foldedLines, foldedLines / totalLines * 100)
            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)
                    if curWidth + chunkWidth < targetWidth then
                        suffix = suffix .. (" "):rep(targetWidth - curWidth - chunkWidth)
                    end
                    break
                end
                curWidth = curWidth + chunkWidth
            end
            local rAlignAppndx = math.max(math.min(vim.opt.textwidth["_value"], width - 1) - curWidth - sufWidth, 0)
            suffix = (" "):rep(rAlignAppndx) .. suffix
            table.insert(newVirtText, { suffix, "MoreMsg" })
            return newVirtText
        end
        opts["fold_virt_text_handler"] = handler
        require("ufo").setup(opts)

        vim.fn.sign_define("FoldClosed", { text = "▸", texthl = "Folded" })
        vim.fn.sign_define("FoldOpen", { text = "▾", texthl = "Folded" })
        vim.fn.sign_define("FoldSeparator", { text = " ", texthl = "Folded" })
    end,
}

Is there something I am missing?
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests