1

I often don't remember what was copied lately. So I don't know if I need to do <C-r>0 or <C-R>1 in insert mode.

I tend to rely only on the * register, or type :reg, look at everything and then decide.

This is cumbersome. Is there a better way to do this?

0

Some mappings to know what inside each register.

ctrl_q+REG for insert mode. 'R+REG' for other modes. Displays the content of register REG. For example, R0 - displays register 0 content.

Replaced the not so useful R.

This function maps all registers so that we know what we have in each.

nnoremap <leader>R R
func! MapR()
    let lst=['+','*']
    for i in range(10)
        call add(lst,string(i))
    endfor
    let k=char2nr('a')
    for j in range(26)
        call add(lst,nr2char(k+j))
    endfor 
    echo lst
for i in lst 
        exec 'nmap R'. i .' :echo getreg("'.i .'")<CR>'
        exec 'vmap R'. i .' <CMD>:echo getreg("'.i .'")<CR>'
        exec 'imap <c-q>'. i .' <CMD>:echo getreg("'.i .'")<CR>'
endfor 
endf

call MapR()
0

I arranged that when I press <C-L> it toggles yank mode, in which the usual status line turns into a line displaying the yank regs. I use Airline.

function! GetLine(timer)
    if !exists('g:reg_tog')
        return 
    endif
    if g:reg_tog==0 
        return
    endif 
    if (getreg('0')==getreg('*'))
        let regs=['+','1','2','3','x','z','4','5']
    else
        let regs=['*','0','1','2','x','z','4','5']
    endif 

    let tot=0
    let wid=winwidth(0)
    let s=""
    let tl=0
    let avg=0

    let countmore=0
    let lenlessthan=0
    let lenmore=0

    for it in regs
        let t=printf('%s',getreg(it))
        let t=substitute(t,"\<NL>","^M","g")
        let t=substitute(t,"\t","    ","g")
        let l= len(t) 

        if l<(wid-25)/(len(regs)+1)
            let lenlessthan+=l
        else
            let lenmore+=l 
            let countmore+=1
        endif 
    endfor 

    let neededavg = ((wid-25-(3*countmore)) - lenlessthan + 0.01) / (countmore+ 0.01)



    for it in regs
        let t=printf('%s',getreg(it))
        let t=substitute(t,"\<NL>","","g")
        let t=substitute(t,"\t","    ","g")
        let l= len(t) 
        if  l>=(wid-25)/(len(regs)+1) 
            let ll=min([len(t),float2nr(floor(neededavg))])
        else
            let ll=len(t)
        endif 
        if ll>0
            if (len(s)+ll<wid-25)
                if ll<l
                    let s=s . printf('%s',it) . ': ' . t[0:ll] .'..| '
                else
                    let s=s . printf('%s',it) . ': ' . t[0:ll] .' | '
                endif 
            endif
        endif
    endfor
    let g:line=s
endfunction

function! RegsToggle()
    if !exists('g:reg_tog')
        let g:reg_tog=0
    endif


    let g:reg_tog=!(g:reg_tog)
    if g:reg_tog
        let g:airline_section_a_temp= g:airline_section_a
        let g:airline_section_a=""
        let g:airline_section_x_temp= g:airline_section_x
        let g:airline_section_x=""
        let g:airline_section_y_temp= g:airline_section_y
        let g:airline_section_y=""
        let g:airline_section_z_temp= g:airline_section_z
        let g:airline_section_z=""
        let g:airline_section_c= "%{g:line}"
        "*=  %-0.40{printf('%s',getreg('*'))}  0=  %-0.40{printf('%s',getreg(0))}  1= %-0.40{printf('%s',getreg(1))}  2= %-0.40{printf('%s',getreg(2))} 3= %-0.40{printf('%s',getreg(3))} x= %-0.40{printf('%s',getreg('x'))}"
        let g:airline_section_error_temp= g:airline_section_error
        let g:airline_section_error=""
        let g:airline_section_warning_temp= g:airline_section_warning
        let g:airline_section_warning=""
    else
        let g:airline_section_error= g:airline_section_error_temp
        let g:airline_section_warning = g:airline_section_warning_temp
        let g:airline_section_a= g:airline_section_a_temp
        let g:airline_section_x= g:airline_section_x_temp
        let g:airline_section_y= g:airline_section_y_temp
        let g:airline_section_z= g:airline_section_z_temp
        let g:airline_section_c= '%<%{tabpagenr()} %<%{getcwd()} | %f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#'
    endif
    :AirlineRefresh
    "call airline#extensions#tabline#buflist#invalidate()
    ":redraw!
endfunction


let g:autoreg=timer_start(2000,'GetLine',{'repeat':-1})

and added

nnoremap <C-L> :call RegsToggle()<CR>

Notice that added timer. Notice that my c part is different in the usual display since it contains the current working directory.

so you can add

let g:airline_section_c= '%<%{getcwd()} | %f%m %#__accent_red#%{airline#util#wrap(airline#parts#readonly(),0)}%#__restore__#'

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.