" 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 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=toc#fold(v:lnum) setlocal foldtext=toc#fold_tex() endif " Define mappings nnoremap G G4k nnoremap OA k nnoremap OB j nnoremap OC l nnoremap OD h nnoremap s :call toc_toggle_numbers() 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) " {{{1 s:toc_activate function! s:toc_activate(close) let n = getpos('.')[1] - 1 if n >= len(b:toc) return endif let entry = b:toc[n] let titlestr = s:toc_escape_title(entry['text']) " Search for duplicates let i=0 let entry_hash = entry['level'].titlestr let duplicates = 0 while i\s*{\?', '.*', 'g') let titlestr = substitute(titlestr, '}', '', 'g') let titlestr = substitute(titlestr, '\%(\.\*\s*\)\{2,}', '.*', 'g') return titlestr endfunction " {{{1 s:toc_find_match function! s:toc_find_match(strsearch, duplicates, files) if len(a:files) == 0 echoerr "Could not find: " . a:strsearch return endif call s:toc_open_buf(a:files[0]) let dups = a:duplicates " Skip duplicates while dups > 0 if search(a:strsearch, 'w') let dups -= 1 else break endif endwhile if search(a:strsearch, 'w') normal! zv return endif call s:toc_find_match(a:strsearch, dups, a:files[1:]) endfunction " {{{1 s:toc_open_buf function! s:toc_open_buf(file) let bnr = bufnr(a:file) if bnr == -1 execute 'badd ' . a:file let bnr = bufnr(a:file) endif execute 'buffer! ' . bnr normal! gg endfunction " {{{1 s:toc_toggle_numbers function! s:toc_toggle_numbers() if b:toc_numbers setlocal conceallevel=3 let b:toc_numbers = 0 else setlocal conceallevel=0 let b:toc_numbers = 1 endif endfunction " }}}1 " vim: fdm=marker