vim-ledger
vim-ledger copied to clipboard
Long comments should wrap to new lines
When typing a comment, it wraps to the same line instead of wrapping to a new line.
https://github.com/ledger/vim-ledger/assets/390059/2faa926c-08f2-4b52-bf28-b921d050e600
I haven't done any extra customizations to the plugin. I am on the bleeding edge of Vim 9.
That's somewhat surprising! And I've never seen anything like it..
I'm on NeoVIM 0.10 over here, but definitely don't have the same problem:
I'm pretty skeptical that only this plugin alone is causing such a problem, this seems like some weird plugin interaction bug.
Yup! Beats me too. The closest I've come to debugging this is… for some reason, formatoptions=tcqj is not being respected.
:h fo-table says this is meant to
tautowrap text usingtextwidthcautowrap comments usingtextwidthqenable formatting withgqjremove the comment character when joining lines
Doesn't look like Neovim is autowrapping comments either — peep the … that indents there. Looks to me like the line ran out of screen space
My formatoptions is set to tcqlr12Bj by default, but I just tried your settings (again my end is NeoVIM) and didn't see a problem.
Are you sure you don't have this issue with other file types?
Holy sheet! I found it 😭😭😭
https://github.com/ledger/vim-ledger/blob/7b97c8765bf920e92fd950a7a5bc37cb2b13a494/ftplugin/ledger.vim#L23
ledger#align_formatexpr is effectively ledger#align_commodity which may not be applicable to comments. Commenting out this line — the one that sets is as formatexpr — fixes the issue. We don't want to incessantly format while we type. :LedgerAlign and :LedgerAlignBuffer can do the job after the typing is done.
On comment lines, it causes the behaviour in the OP. On transaction lines it actually hangs Vim. — I'm curious to see what it does in Neovim.
How to test?
- Enter a simple transaction, like the "example" below
- I have the
payeelong enough to marktextwidth
- I have the
- Indent the transaction line so a comment goes to
textwidth- …just so we can notice the hang point clealy
- Type some one or two characters afterwards`
- Notice Vim hangs
- Use
<C-c>to unhang it
Example
2023-01-01 * lskdjfl skdjf lsdkjflskdjf lskdjf lsdkjf lskdjf lskdjf lksdjf lksdj
Expenses 92837923 USD ; lsdkfsdlfksj-X-kjl
; ^
; |
; here
I just tested this out in Neovim and it doesn't seem to be a problem. The lines don't wrap, but it doesn't hang either
Hold that thought…
In Neovim, g:ledger_max_width=0 (i.e. textwidth=0) — this may be the reason we don't see the problem in Neovim
NVM it's the same in Vim as well. I don't know why it breaks in Vim and not in Neovim
But commenting out the formatexpr line works for me