Skip to content

Instantly share code, notes, and snippets.

@pi314
Last active October 14, 2015 13:31
Show Gist options
  • Save pi314/9076247c8d64b46d2e89 to your computer and use it in GitHub Desktop.
Save pi314/9076247c8d64b46d2e89 to your computer and use it in GitHub Desktop.
A little vim plugin used to display an reStructuredText-like slide in CCCA x SITCON meet up, 2015/10/14
" ============= "
" filetype.vim "
" ============= "
au BufNewFile,BufRead slide setf slide.rst
au BufNewFile,BufRead *.slide setf slide.rst.todo
" =================== "
" ftplugin/slide.vim "
" =================== "
setlocal scrolloff=0
nnoremap <CR> :call Show_next_item()<CR>
let s:backuped = 0
function Show_next_item ()
if !s:backuped
normal! :w slide.backup
let s:backuped = 1
endif
let l:hidden_bullet_nu = s:exist_hidden_bullets()
if l:hidden_bullet_nu
call s:show_one_hidden_bullet(l:hidden_bullet_nu)
else
call s:next_page()
endif
endfunction
function s:exist_hidden_bullets ()
normal! gg
let l:i = 1
while 1
let l:line = getline(l:i)
if l:line =~# '\v^ *#.*$'
return l:i
elseif l:line ==# '<hide>'
return 0
endif
let l:i = l:i + 1
endwhile
return 0
endfunction
function! s:show_one_hidden_bullet (nu)
call cursor(a:nu, 1)
normal! ^r*
endfunction
function s:next_page ()
" delete current page
normal! /<hide>
kkdgg
normal! d2j
normal! 4gg
normal! /\v^\=+
normal! O----
<hide>
normal! gg
endfunction
" ================ "
" syntax/slide.vim "
" ================ "
syn match rstBulletList /\(^\ *\)\@<=#\(\ \)\@=/
syn match hidden_text _^ *#.*$_
syn region hidden_text start=_<hide>_ end=_<stophide>_
hi hidden_text ctermfg=black
syn match todo_string _\v"([^\\"]|\\.)*"_
hi def todo_string ctermfg=LightMagenta
syn match Google_G _\v<G(oogle>)@=_
syn match Google_first_o _\v(<G)@<=o(ogle>)@=_
syn match Google_second_o _\v(<Go)@<=o(gle>)@=_
syn match Google_g _\v(<Goo)@<=g(le>)@=_
syn match Google_l _\v(<Goog)@<=l(e>)@=_
syn match Google_e _\v(<Googl)@<=e>_
hi def Google_G cterm=bold ctermfg=blue
hi def Google_first_o cterm=bold ctermfg=red
hi def Google_second_o cterm=bold ctermfg=yellow
hi def Google_g cterm=bold ctermfg=blue
hi def Google_l cterm=bold ctermfg=green
hi def Google_e cterm=bold ctermfg=red
syn match Yahoo _\v<Yahoo!_
hi def Yahoo cterm=bold ctermfg=magenta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment