setlocal spell setlocal textwidth=0 setlocal syntax=rmd setlocal breakat-=@ setlocal makeprg=Rscript\ -e\ 'publishR::render(\\"%\\")' nnoremap oh :! xdg-open %:r.html nnoremap op :! xdg-open %:r.pdf nnoremap ow :! xdg-open %:r.docx nnoremap t :TOC xnoremap ic :call InnerChunk() onoremap ic :call InnerChunk() xnoremap ac :call OuterChunk() onoremap ac :call OuterChunk() function OuterChunk() let chunk = FindChunk() execute "normal! " . chunk.start . "GV" . chunk.end . "G" endfunction function InnerChunk() let chunk = FindChunk() execute "normal! " . chunk.start . "GjV" . chunk.end . "Gk" endfunction function FindChunk() let view = winsaveview() normal! j ?\v^ *```(\{.*\})=$ let startFence = line(".") /\v^ *``` * let endFence = line(".") if startFence <= view.lnum && endFence >= view.lnum return {"start": startFence, "end": endFence} else echoerr "Not inside a chunk" endif call winrestview(view) endfunction