Skip to content

Instantly share code, notes, and snippets.

@nhooyr
Created December 30, 2016 19:25
Show Gist options
  • Save nhooyr/7c171fd199f7efa715abbc06d50d7b92 to your computer and use it in GitHub Desktop.
Save nhooyr/7c171fd199f7efa715abbc06d50d7b92 to your computer and use it in GitHub Desktop.
function! man#highlight_backspaced_text() abort
set modifiable
let b = nvim_get_current_buf()
while 1
let pos = searchpos('\%(.\b.\)\+')
if pos[0] == 0
break
endif
let pos[0] -= 1
let pos[1] -= 1
silent keepjumps substitute/\%(.\b.\)\+/\=execute("let match = substitute(submatch(0), '.\\b', '', 'g') | let isUnderline = submatch(0)[0] ==# '_'").match
if isUnderline
call nvim_buf_add_highlight(b, -1, 'manUnderline', pos[0], pos[1], pos[1]+len(match))
else
call nvim_buf_add_highlight(b, -1, 'manBold', pos[0], pos[1], pos[1]+len(match))
endif
endwhile
set nomodifiable
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment