I know this can look a lot like a duplicate of Vim wrap only current line, but none of the answers give a real solution to the original problem, as all of them state that per-line soft wrapping is not possible, proposing alternatives like hard wrapping the line and undoing the change afterwards, or showing the wrapped line in an ad-hoc buffer.
Furthermore, 6 years have passed, Vim has improved, and I wonder if new solutions exist.
A strategy that looks promising to me is to have an autocmd CursorHold
showing a popup populated by the current line only, with horizontal scrolling taking into account stuff I use all the time, like number
, relativenumber
, list lcs
.
Leaving aside for now the autocmd
/augroup
part of the strategy, what I've come up with is the following,
function! Foo()
call popup_create(getline('.'),
\ #{ line: 'cursor', col: screencol() - virtcol('.') + 1, moved: [line('.'), 0, col('$')], })
endfunction
which does a pretty good job in terms of formatting,
Except that the line is not syntax-colored (the 3
would have to be the same color as the other digits a few lines above).
I've found out that the first argument to popup_create
can be a buffer number, which means that popup will be populated with that buffer. This seems useful, but I haven't been able to use it to show only the current line. I can start from the current line, via firstline
option, but don't know how to set a final line, as lastline
doesn't do the job¹ (probably I don't understand what it is for). Here's the second attempt I'm referring to:
function! Foo()
call popup_setoptions(
\ popup_create(
\ bufnr('.'),
\ #{ line: 'cursor', col: screencol() - virtcol('.') + 1, moved: [line('.'), 0, col('$')], }
\ ),
\ #{ wrap: 1, firstline: line('.')})
endfunction
Well, there's also the problem of the background of the popup, but that's likely easier to fix.
(¹) In the sense that I get the same output as the one in second screenshot, whther or not I put lastline: line('.') + 1
or lastline: line('.')
in in popup_setoptions
's second argument.
lastline: line('.') + 1
? Also test without +1. Adding info to the question helps.