comment-box.nvim icon indicating copy to clipboard operation
comment-box.nvim copied to clipboard

Intendation isn't preserved

Open savchenko opened this issue 2 years ago • 2 comments

Not sure how I haven't noticed this before, but...

https://github.com/LudoPinelli/comment-box.nvim/assets/300146/5f07257b-6850-4a0e-92ea-301b150f69ee

...can it take into account current indent level?

savchenko avatar Jan 16 '24 04:01 savchenko

I didn't think about that since I use an autoformat on save that restore the indentation. I'll look into it!

LudoPinelli avatar Jan 16 '24 07:01 LudoPinelli

If that is of any help, carved out of my old Vim config:

" Insert cut marker (https://stackoverflow.com/a/59291748)
function Cut() abort
    if &textwidth
        execute "normal! mg"
        " let l:str = input('Char: ')
        let l:str = '-'
        .s/\m\(\S\+\)$/\1 /e  " Add space after content (if present).

        " Calculate how many repetitions will fit.
        let l:lastcol = col('$')-1  " See :h col().
        if l:lastcol > 1
            let l:numstr = float2nr(floor((&textwidth-l:lastcol)/len(l:str)))
        else
            let l:numstr = float2nr(floor(&textwidth/len(l:str)))
        endif

        if l:numstr > 0
            set lazyredraw
            .s/\m$/\=(repeat(l:str, l:numstr))/  " Append repeated pattern.
            execute "normal! `g"
            :delmarks g
            set nolazyredraw
        endif
    else
        echohl WarningMsg
        echom "Cut requires nonzero textwidth setting"
        echohl None
    endif
endfunction

savchenko avatar Feb 01 '24 12:02 savchenko