以下函数应创建一个仅包含前导码和当前帧的新临时文件。它以拆分方式打开文件,从那时起,您应该能够单独编译该文件并使用您执行的任何程序来查看它。我对 tex 了解不多,对 beamer 的了解更少,因此您可能需要对其进行调整以更好地满足您的需求。
function! CompileBeamer()
" Collect the lines for the current frame:
let frame = []
if searchpair('\\begin{frame}', '', '\\end{frame}', 'bW') > 0
let frame = s:LinesUpto('\\end{frame}')
call add(frame, getline('.')) " add the end tag as well
endif
" Go to the start, and collect all the lines up to the first "frame" item.
call cursor(1, 1)
let preamble = s:LinesUpto('\\begin{frame}')
let body = preamble + frame
" Open up a temporary file and put the selected lines in it.
let filename = tempname().'.tex'
exe "split ".filename
call append(0, body)
set nomodified
endfunction
function! s:LinesUpto(pattern)
let line = getline('.')
let lines = []
while line !~ a:pattern && line('.') < line('$')
call add(lines, line)
call cursor(line('.') + 1, 1)
let line = getline('.')
endwhile
return lines
endfunction