junegunn / limelight.vim

:flashlight: All the world's indeed a stage and we are merely players
MIT License
2.36k stars 53 forks source link

Limelight on per-line basis #40

Closed sudo-nice closed 7 years ago

sudo-nice commented 7 years ago

Thank you for a very helpful plugin. Could you, please, advice me a solution to get only the current line highlighted with limelight? My approaches are all around this config:

let g:limelight_bop = '^'
let g:limelight_eop = '$'

If the cursor moves not to the end of the next/previous line, it works well. Here the example where the cursor moved from the middle of line 1 to the middle of the line 2: scr1

However if the cursor moves to the end of the next/previous line, the next line and the line after next get highlighted both: scr2

Have I overlooked any simple solution here?

franckrasolo commented 5 years ago

In case this helps others, the solution to the above is:

let g:limelight_bop = '^.*$'
let g:limelight_eop = '\n'
let g:limelight_paragraph_span = 0
aviloff commented 2 years ago

@franckrasolo i'm still getting the problem with double line highlighting though

amariusz commented 7 months ago

Again, in case this help others, I think @sudo-nice solution was OK but matching pattern '$' at the end of line does not work due to this line:

https://github.com/junegunn/limelight.vim/blob/86aaec1700b27618d33d6182f44691d84d2cb6e5/autoload/limelight.vim#L55

After changing it from let end = searchpos(eop, 'W')[0] to let end = searchpos(eop, 'Wc')[0] the problem with double line highlighting seems to be gone.

c flag means:

    'c' accept a match at the Cursor position

However it's probably worth noting - the speed is not great, especially while moving cursor up and down over a file with long lines.

amariusz commented 7 months ago

Turned out this solution does not work properly if g:limelight_paragraph_span is set value greater then 0 so I've reverted the flag change. Instead I've added moving cursor to the beginning of line (normal 0) just before the for loop.

  call setpos('.', pos)
  normal 0
  for _ in range(0, span)
    let end = searchpos(eop, 'W')[0]
  endfor

(Cursor position is restored later in the script)

This seems to be working fine with g:limelight_paragraph_span

kevinlawler commented 1 month ago

@amariusz that solution breaks on single-character lines

aaaa
bbbb
cccc
a
b
c

Adding the c flag back seems to solve it? I haven't tested this thoroughly.

Working config arguments seem to be the basic:

let g:limelight_bop = '^'
let g:limelight_eop = '$'
kevinlawler commented 1 month ago
!normal 0 && !c-flag breaks g:limelight_paragraph_span == 0, status quo
!normal 0 &&  c-flag breaks g:limelight_paragraph_span != 0
 normal 0 && !c-flag breaks g:limelight_paragraph_span != 0 for lines of single char
 normal 0 &&  c-flag breaks g:limelight_paragraph_span != 0 (but works for == 0)

needs a separate fix to not break g:limelight_paragraph_span != 0

if you only need g:limelight_paragraph_span = 0, however, it works

78