" LaTeX plugin for Vim " " Maintainer: Karl Yngve LervÄg " Email: karl.yngve@gmail.com " if exists('b:did_ftplugin') finish endif let b:did_ftplugin = 1 " Set local buffer settings setlocal buftype=nofile setlocal bufhidden=wipe setlocal listchars= setlocal nobuflisted setlocal noswapfile setlocal nowrap setlocal nonumber setlocal nolist setlocal nospell setlocal cursorline setlocal tabstop=8 setlocal cole=0 setlocal cocu=nvic if g:latex_toc_fold setlocal foldmethod=expr setlocal foldexpr=latextoc#fold_level(v:lnum) setlocal foldtext=latextoc#fold_text() endif " Refresh/Initialize TOC content call latextoc#refresh() " Define mappings nnoremap G G4k nnoremap OA k nnoremap OB j nnoremap OC l nnoremap OD h nnoremap s :call toc_toggle_numbers() nnoremap - :call toc_dec_secnumdepth() nnoremap + :call toc_inc_secnumdepth() nnoremap q :call toc_close() nnoremap :call toc_close() nnoremap :call toc_activate(0) nnoremap :call toc_activate(0) nnoremap :call toc_activate(1) nnoremap <2-leftmouse> :call toc_activate(1) function! s:toc_activate(close) "{{{1 " Get TOC entry, do nothing if no entry found " entry = { " title : ..., " number : ..., " file : ..., " line : ..., " } let n = getpos('.')[1] - 1 if n >= len(b:toc) return endif let entry = b:toc[n] " Save TOC buffer info for later use let toc_bnr = bufnr('%') let toc_wnr = winnr() " Return to calling window execute b:calling_winnr . 'wincmd w' " Open file and line for given TOC entry call s:toc_open_entry(entry) " Keep or close TOC window (based on options) if a:close if g:latex_toc_resize silent exe "set columns-=" . g:latex_toc_width endif execute 'bwipeout ' . toc_bnr else execute toc_wnr . 'wincmd w' endif endfunction function! s:toc_close() "{{{1 if g:latex_toc_resize silent exe "set columns-=" . g:latex_toc_width endif bwipeout endfunction function! s:toc_open_entry(entry) "{{{1 " Open file buffer let bnr = bufnr(a:entry.file) if bnr == -1 execute 'badd ' . fnameescape(a:entry.file) let bnr = bufnr(a:entry.file) endif execute 'buffer! ' . bnr " Go to entry line call setpos('.', [0, a:entry.line, 0, 0]) " Ensure folds are opened normal! zv endfunction function! s:toc_toggle_numbers() "{{{1 if b:toc_numbers let b:toc_numbers = 0 else let b:toc_numbers = 1 endif call latextoc#refresh() endfunction function! s:toc_inc_secnumdepth() "{{{1 let b:toc_secnumdepth += 1 let g:latex_toc_secnumdepth = b:toc_secnumdepth call latextoc#refresh() endfunction function! s:toc_dec_secnumdepth() "{{{1 let b:toc_secnumdepth -= 1 let g:latex_toc_secnumdepth = b:toc_secnumdepth call latextoc#refresh() endfunction " }}}1 " vim: fdm=marker