0

How to display extra column before/after line numbers , and modify , programmatically, using Vimscript?

Maybe some examples of existing plugins doing so, that I could base of?

(this could be great basis/start for Marking/Annotating lines with symbols (with external storage) )

*  1 This
?  2 is
T  3 test
!  4 file.

-- INSERT --     4,6  All

OR on the right side of numbers

  1* This
  2? is
  3T test
  4! file.

-- INSERT --     4,6  All
2

1 Answer 1

1

Thanks to @d-ben-knoble :help sign is the answer + making sure you do not have turned on merging line number and sign column in your .vimrc (check for signcolumn in your .vimrc files).

From :help sign :

:sign define piet text=>> texthl=Search
:exe ":sign place 2 line=23 name=piet file=" . expand("%:p")
" and
:sign unplace 2
" or
:sign unplace all

If you want to see example of vimscript snippet using it, here is my current version of snippet in .vimrc

" ################
sign define byA text=+A

" Highlights lines specified in file
" call using :call HL()
function! HL()
  execute 'sign unplace * file='.expand('%:p')
  for i in readfile($HOME.'/.cache/HL/l.txt')
    "echom 'Highlighting '.i
    call matchadd('LineHighlight', '\%'.i.'l')
    execute ':sign place '.(123000+i).' line='.i.' name=byA file='.expand('%:p')
  endfor
endfunction

" Adds current line to file
function! AddLineToHL()
    silent execute '! echo '.line('.').' | tee -a '.$HOME.'/.cache/HL/l.txt'
    call HL()
    redraw!
endfunction
" and add shortcut (usually [\]+[l])
nnoremap <Leader>l :call AddLineToHL()<CR>

" ###############

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.