Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- " 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
Add Comment
Please, Sign In to add comment