Guest User

Untitled

a guest
Jan 19th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. " Create the mapping which will toggle the cheatsheet
  2. nnoremap <F1> :call Cheatsheet()<CR>
  3.  
  4. function! Cheatsheet()
  5. " Save the z register
  6. let save_z = getreg('z')
  7.  
  8. " Get the list of buffers in the z register
  9. redir @z
  10. silent filter /cheatsheet/ ls
  11. redir END
  12.  
  13. " Get the result in a variable and restore the register
  14. let buff = getreg('z')
  15. call setreg('z', save_z)
  16.  
  17. " The results has several lines, make it only one
  18. let buff = substitute(buff, 'n', '', 'g')
  19.  
  20. " Get the status (hiden 'h' or not 'a') of the buffer
  21. let status = buff[match(buff, '[ah]')]
  22.  
  23. " If the buffer is not hidden delete it, that will close the split
  24. if status == "a"
  25. let buffnumber = substitute(buff, '^s*', '', '')[0]
  26. execute "bdelete " . buffnumber
  27. " Else open a split
  28. else
  29. vsplit ~/.cheatsheet
  30. endif
  31. endfunction
Add Comment
Please, Sign In to add comment