kevinhwang91 / nvim-ufo

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

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

Closed CRAG666 closed 1 year ago

CRAG666 commented 2 years ago

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

kevinhwang91 commented 2 years ago
  1. vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]
  2. vim.o.foldcolumn = '1'
  3. need this PR https://github.com/neovim/neovim/pull/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 commented 2 years ago

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]);
CRAG666 commented 2 years ago

Tanks

hisamafahri commented 2 years ago

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

kevinhwang91 commented 2 years ago

For now, must compile Neovim source code.

bandithijo commented 2 years ago

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 https://github.com/kevinhwang91/nvim-ufo/issues/4#issuecomment-1157722074 and recompile. The indent level number indicator will be gone.

data-stepper commented 2 years ago

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 commented 2 years ago

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

kevinhwang91 commented 2 years ago

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 commented 2 years ago

thanks a lot

p00f commented 2 years ago

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

cathaysia commented 2 years ago

How do I change the color of filechars?

kevinhwang91 commented 2 years ago

How do I change the color of filechars?

h FoldColumn

kevinhwang91 commented 2 years ago

I am trying my best to imp https://github.com/kevinhwang91/nvim-ufo/issues/24 which I think is better than VSCode UI. Suggestions are welcome.

diego-treitos commented 2 years ago

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 commented 2 years ago

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

diego-treitos commented 2 years ago

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:

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

alex-popov-tech commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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 commented 1 year ago

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

WhiteBlackGoose commented 1 year ago

Ok so yeah, here's a release folder: https://github.com/WhiteBlackGoose/neovim-goose/releases

WhiteBlackGoose commented 1 year ago

@alex-popov-tech in case you're still lazy to build it yourself :P

airtonix commented 1 year ago

image

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.

Yeah Nah.

okuuva commented 1 year ago
  1. vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]

    1. vim.o.foldcolumn = '1'

    2. 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.

That PR just got closed because 'statuscolumn' got merged in Oct: https://github.com/neovim/neovim/pull/17446#issuecomment-1377139726

Any possibility of ufo getting refactored so that PR won't be necessary? I love the plugin but having to use a fork just for it isn't really feasible if there's no hope of the necessary changes being ever included in neovim.

kevinhwang91 commented 1 year ago
  1. vim.o.fillchars = [[eob: ,fold: ,foldopen:,foldsep: ,foldclose:]]

    1. vim.o.foldcolumn = '1'
    2. 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.

That PR just got closed because 'statuscolumn' got merged in Oct: neovim/neovim#17446 (comment)

Any possibility of ufo getting refactored so that PR won't be necessary? I love the plugin but having to use a fork just for it isn't really feasible if there's no hope of the necessary changes being ever included in neovim.

Look like you should extend statuscolumn option. I don't trace nightly for now. Maybe someone can help.

ricbermo commented 1 year ago

Hi all. How do we achieve the same results with neovim 9 since statuscolumn is now merged? TY

ratheesh commented 1 year ago

Hi all. How do we achieve the same results with neovim 9 since statuscolumn is now merged? TY

Should be able to use a custom expression that follows the 'statusline' syntax. See neovim/neovim#17446 (comment)

I tried it out and got the following: Screenshot 2023-01-10 at 16 48 28

While this works fine, highlighting of the FoldColumn is not respected. CursorLineNr highlights are applied.

image
rockyzhang24 commented 1 year ago

While this works fine, highlighting of the FoldColumn is not respected. CursorLineNr highlights are applied.

The expression you pulled out from that comment is not accurate.

In this expression vim.o.statuscolumn = '%=%l%s%{foldlevel(v:lnum) > foldlevel(v:lnum - 1) ? (foldclosed(v:lnum) == -1 ? "▼" : "⏵") : " " }', the fold column item (i.e., %C) is not specified, and instead it simulates the fold signs by the last part %{...}. That's why FoldColumn highlight group has no effect. If you set it normally like vim.o.statuscolumn = '%=%l%s%C, you will see the fold column is highlighted as expected.

One workaround is using # to set the highlight group as what statusline does. lua vim.o.statuscolumn = '%=%l%s%#FoldColumn#%{foldlevel(v:lnum) > foldlevel(v:lnum - 1) ? (foldclosed(v:lnum) == -1 ? "▼" : "⏵") : " " }%*'

technicalpickles commented 1 year ago

I tweaked the last one to use the same characters as https://github.com/kevinhwang91/nvim-ufo/issues/4#issuecomment-1157716294 , and it fight too tight without any trailing space:

vim.o.statuscolumn = '%=%l%s%#FoldColumn#%{foldlevel(v:lnum) > foldlevel(v:lnum - 1) ? (foldclosed(v:lnum) == -1 ? " " : " ") : "  " }%*'
CleanShot 2023-01-10 at 16 24 18@2x
rockyzhang24 commented 1 year ago

@technicalpickles You could insert any number of spaces you want between any two items.

okuuva commented 1 year ago

Thanks @rockyzhang24! To me it seems that with statuscolumn it's possible to replicate the appearance of the foldcolumn as seen in the demo, and then some. Unfortunately statuscolumn also messes up pretty much every other plugin because it gets drawn where there didn't use to be any line numbers 😅 But such is life when running the nightly builds. And the good news is that this issue can probably be closed when 0.9 is released.

kevinhwang91 commented 1 year ago

https://github.com/neovim/neovim/pull/17446#issuecomment-1378706377

EtiamNullam commented 1 year ago

We can use some fold indication as we already have foldcolumn taking our space (based on https://github.com/kevinhwang91/nvim-ufo/issues/4#issuecomment-1377887123):

vim.o.statuscolumn = '%s%=%l %#FoldColumn#%{'
  .. 'foldlevel(v:lnum) > foldlevel(v:lnum - 1)'
    .. '? foldclosed(v:lnum) == -1'
      .. '? "-"'
      .. ': "+"'
    .. ': foldlevel(v:lnum) == 0'
      .. '? " "'
      .. ': "·"'
..'} '

- - open, + - closed, · - fold body, - no fold. Adjust to your needs.

image

NOTE: I'm not using nvim-ufo.

technicalpickles commented 1 year ago

I was able to figure out a way to not show line numbers when they've been turned off for a buffer:

CleanShot 2023-01-12 at 11 13 26

vim.o.statuscolumn = '%= '
  .. '%s' -- sign column FIXME: figure out how to put on the other side without having to do a lot of shifting
  .. '%{%' -- evaluate this, and then evaluate what it returns
    .. '&number ?'
      .. '(v:relnum ?'
        .. 'printf("%"..len(line("$")).."s", v:relnum)' -- when showing relative numbers, make sure to pad so things don't shift as you move the cursor
      .. ':'
        .. 'v:lnum'
      .. ')'
    .. ':'
      .. '""'
    .. ' ' -- space between lines and fold
  .. '%}'
  .. '%= '
  .. '%#FoldColumn#' -- highlight group for fold
  .. '%{' -- expression for showing fold expand/colapse
    .. 'foldlevel(v:lnum) > foldlevel(v:lnum - 1)' -- any folds?
      .. '? (foldclosed(v:lnum) == -1' -- currently open?
        .. '? ""' -- point down
        .. ':  ""' -- point to right
    .. ')'
    .. ': " "' -- blank for no fold, or inside fold
  .. '}'
  .. '%= ' -- spacing between end of column and start of text

The only issue I have right now is about the signcolumn, where it can shift around a bit especially if there's multiple diagnostics on one line but that might be more configuration in diagnostics/signcolumn.

rockyzhang24 commented 1 year ago

Seems 'statuscolumn' has been abused. It should be used for arranging items, not introducing complicated logics which may bring extra performance overhead. Mimicking a foldcolumn looking by an expression instead of the real item %C is not a good idea. Because that is not a real foldcolumn, some features provided by ufo become unavailable (e.g., the click feature). We should have a choice to config what should be shown on the foldcolumn (like this closed PR https://github.com/neovim/neovim/pull/17446) and then use %C directly in 'statuscolumn'.

kevinhwang91 commented 1 year ago

https://user-images.githubusercontent.com/17562139/212465689-fbc3e667-914d-4ea3-9969-83d949f0c594.mp4 The left pane is using statuscolumn and the right pane hack Neovim by changing source code.

The perf is not an issue. But need a module with hundreds of LOC , simple expr is buggy. TBH, statuscolumn is unproductive and unconsidered, there are some issues. However, I'm not interested in it. Just telling guys ufo can finish this feature with statuscolumn .

okuuva commented 1 year ago

@kevinhwang91 not sure what you meant with the last comment.

But need a module with hundreds of LOC , simple expr is buggy.

A module with hundreds lines of code? What, where?

TBH, statuscolumn is unproductive and unconsidered, there are some issues. However, I'm not interested in it.

If you meant to say that emulating fold column with status column is a dirty hack, you're absolutely right. There really should be a way to configure the fold column appearance separately and just use statuscolumn as a format string for status column components instead of evaluating complex expressions. But before we get that, statuscolumn hacks can be used to simulate fold column without having to use a self compiled fork of neovim.

Sorry if I come out as aggressive or confrontational, that's absolutely not my intent. Just trying to figure out what you meant by that last comment.

EtiamNullam commented 1 year ago

@okuuva: If you didn't notice @kevinhwang91 is the owner of this repo, so I think he is talking about lack of plans for implementing statuscolumn hacks in nvim-ufo, as he finds it unproductive.

I believe we need a better solution for configuring it in neovim itself, but we can get pretty decent output using those "hacks" for now :P

kevinhwang91 commented 1 year ago

@okuuva

A module with hundreds lines of code? What, where?

Local, don't want to open it now, I just give statuscolumn a try to make it work perfectly with ufo.

You should think about why statuscolumn didn't merge into Vim and how to get better perf for this opt, so you can understand why I say it's unproductive and unconsidered. I'm not interested in the issue about statuscolumn, I just make sure ufo is fantastic and keep the users away from trouble.

If statuscolumn will not be changed, I just give an expr API for VSCode like fold column, user doesn't need to write any module and just invoke this API will work perfectly. If statuscolumn becomes easy to use and gets high perf, fold expr should write by users instead of ufo.

okuuva commented 1 year ago

@EtiamNullam

If you didn't notice @kevinhwang91 is the owner of this repo, so I think he is talking about lack of plans for implementing statuscolumn hacks in nvim-ufo, as he finds it unproductive.

I did, I just asked to clarify things for myself since I don't want to assume anything.

@kevinhwang91

Local, don't want to open it now, I just give statuscolumn a try to make it work perfectly with ufo.

Ok, got it now. Thank you for your awesome work 🙏🏼

mehalter commented 1 year ago

One thing I've noticed is using the foldlevel of the current line and the previous line is not sufficient when there are 2 different folds (one ending and one immediately starting) of the same level it is unable to tell that the previous fold has finished. The original image shared in this issue is a good example of several level 2 folds in a row.

This makes the statuscolumn extremely insufficient at identifying folds without the addition of new functions

kevinhwang91 commented 1 year ago

https://github.com/luukvbaal/statuscol.nvim/issues/3

Racle commented 1 year ago

luukvbaal/statuscol.nvim#3

One of the easiest solutions.

Here's quick config which works for me:

    -- packer
    use {
      "kevinhwang91/nvim-ufo",
      requires = {
        "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

        }
      }
    }

and

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:]]

-- these are "extra", change them as you like
vim.keymap.set("n", "zR", require("ufo").openAllFolds)
vim.keymap.set("n", "zM", require("ufo").closeAllFolds)

-- Option 3: treesitter as a main provider instead
-- Only depend on `nvim-treesitter/queries/filetype/folds.scm`,
-- performance and stability are better than `foldmethod=nvim_treesitter#foldexpr()`
require("ufo").setup(
  {
    provider_selector = function(bufnr, filetype, buftype)
      return {"treesitter", "indent"}
    end
  }
)
rsdubtso commented 1 year ago

Hi, how do I enable the vertical indentation/folding level indicators?

rockyzhang24 commented 1 year ago

@rsdubtso Put set foldcolumn=1 in your nvim config. For lua, use vim.o.foldcolumn = '1' instead. For more details, see :h foldcolumn.

If this is not what you need, may I ask what you mean by vertical indentation/folding level indicator? Can you attach a pic please?

rsdubtso commented 1 year ago

Thanks! Sorry, I should have been more clear, I mean the vertical indicators inside the text, like on this picture:

image
Racle commented 1 year ago

@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 commented 1 year ago

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

rsdubtso commented 1 year ago

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