0

To learn my mappings, I want to toggle an individual help (like e.g. a cheatsheet or so).

I don't know how to toggle showing of a window, is there any way or neat key map to toggle something like ":split ~/.vim_help" (with low height of the new window)? The purpose is to show my helpfile quickly, look for the command I can't remember and close (toggle) it then?

1

This is not the shortest solution (nor the most elegant) but you can use it as a basis and tailor it to fit your needs:

" Create the mapping which will toggle the cheatsheet
nnoremap <F1> :call Cheatsheet()<CR>

function! Cheatsheet()
    " Save the z register
    let save_z = getreg('z')

    " Get the list of buffers in the z register
    redir @z
        silent filter /cheatsheet/ ls
    redir END

    " Get the result in a variable and restore the register
    let buff = getreg('z')
    call setreg('z', save_z)

    " The results has several lines, make it only one
    let buff = substitute(buff, '\n', '', 'g')

    " Get the status (hiden 'h' or not 'a') of the buffer
    let status = buff[match(buff, '[ah]')]

    " If the buffer is not hidden delete it, that will close the split
    if status == "a"
        let buffnumber = substitute(buff, '^\s*', '', '')[0]
        execute "bdelete " . buffnumber
    " Else open a split
    else
        vsplit ~/.cheatsheet
    endif
endfunction

These help topics might be helpful:

|improve this answer|||||

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.