Re: [vim/vim] long lines automatically become foldable even with set nowrap (Issue #21000)
cjxgm (Vim Github Repository) <[email protected]>
| Newsgroups | gmane.editors.vim.devel |
|---|---|
| Message-ID | <vim/vim/issues/21000/[email protected]> |
cjxgm left a comment (vim/vim#21000)
Assume you have this physical text in the buffer:
```text
struct foo
{
int x; // a very long long long long physical line.
};
struct bar
{
int a;
int b;
};
struct qux
{
int u;
int v;
int w;
};
```
With `set nowrap` alone, the text would display as (assume the window is only wide enough to show "phy" in the long line, we call it *small window width*):
```text
struct foo
{
int x; // a very long long long long phy
};
struct bar
{
int a;
int b;
};
struct qux
{
int u;
int v;
int w;
};
```
## Initial Case
```vimscript
set nowrap
set foldmethod=expr
set foldexpr=getline(v:lnum)=~'^\\s'?1:0
set foldminlines=1
```
My desired result (with *small window width*):
```text
struct foo
{
int x; // a very long long long long phy
};
struct bar
{
+-- 2 lines: int a;-------------------------
};
struct qux
{
+-- 3 lines: int u;-------------------------
};
```
What Vim actually produces:
```text
struct foo
{
+-- 1 line: int x; // a very long long long
};
struct bar
{
+-- 2 lines: int a;-------------------------
};
struct qux
{
+-- 3 lines: int u;-------------------------
};
```
That is, the long line is foldable and folded now, unexpectedly.
## Case 2: Window Width Affects Folding
Continuing from *Initial Case*. Resize the window wide enough (called *large window width*), and then `set foldminlines=1` again (you must set it again to refresh), and press `zM`, Vim produces:
```text
struct foo
{
int x; // a very long long long long physical line.
};
struct bar
{
+-- 2 lines: int a;---------------------------------------
};
struct qux
{
+-- 3 lines: int u;---------------------------------------
};
```
That is, the long line is unfolded and non-foldable now.
## Case 3: Window Width Indeed Affects Folding
Continuing from *Case 2*. Resize the window back to *small window width*, and `set foldminlines=1` again, and press `zM`, the long line becomes foldable and folded now.
```text
struct foo
{
+-- 1 line: int x; // a very long long long
};
struct bar
{
+-- 2 lines: int a;-------------------------
};
struct qux
{
+-- 3 lines: int u;-------------------------
};
```
## Case 4: Foldminlines Affects More Than Long Lines
Continuing from *Case 3*. Keep the window at *small window width*. But this time, we `set foldminlines=2`.
You guys imply that I can get this:
```text
struct foo
{
int x; // a very long long long long phy
};
struct bar
{
+-- 2 lines: int a;-------------------------
};
struct qux
{
+-- 3 lines: int u;-------------------------
};
```
But Vim actually produces:
```text
struct foo
{
int x; // a very long long long long phy
};
struct bar
{
int a;
int b;
};
struct qux
{
+-- 3 lines: int u;-------------------------
};
```
That is, the long line is indeed unfolded and non-foldable, but `int a` and `int b` lines are also affected by it and becomes unfolded and non-foldable now.
## Case 5: Window Width, Again, Affects Folding
Continuing from *Case 4*. Resize the window to **half** of the *small window width*, and `set foldminlines=2` (set to **2**), press `zM`, Vim produces:
```text
struct foo
{
+-- 1 line: int x; //
};
struct bar
{
int a;
int b;
};
struct qux
{
+-- 3 lines: int u; ---
};
```
That is, the long line is folded again, with `int a` and `int b` unfolded and non-foldable. This looks hilarious.
This is because the long line is wrapped to 3 (or more) lines, so Vim considers it passed the foldminlines restriction.
--
Reply to this email directly or view it on GitHub:
https://github.com/vim/vim/issues/21000#issuecomment-5301150308
You are receiving this because you are subscribed to this thread.
Message ID: <vim/vim/issues/21000/[email protected]>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/vim_dev/vim/vim/issues/21000/5301150308%40github.com.