~telemachus/vim-dotfiles

vim-dotfiles/after/ftplugin/tex.vim -rw-r--r-- 1.5 KiB
33c5d6b7Peter Aronoff Merge 'refs/remotes/origin/main' 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
scriptencoding utf-8
" Basic settings {{{
setlocal tabstop=8 softtabstop=4 shiftwidth=4 expandtab

" Set make to build and open the pdf
setlocal makeprg=latexmk\ -xelatex\ -bibtex\ %\ &&\ open\ build/%:r.pdf

" Soft wrap, please
setlocal textwidth=0
setlocal wrapmargin=0
setlocal wrap
setlocal linebreak
setlocal list
setlocal lazyredraw
setlocal showbreak=" }}}

" Automatically swap `` or '' for " and ` for ' {{{
"
" The TexQuotes and TexQuote methods are adapted from auctex.vim.
" http://www.vim.org/scripts/script.php?script_id=162
function! s:TexQuotes()
    let insert = '"'
    let left = getline('.')[col('.')-2]
    if left =~# '^\(\|\s\)$'
        let insert = '``'
    elseif left ==# '('
        let insert = '``'
    elseif left ==# '\'
        let insert = '"'
    else 
	let insert = "''"
    endif
    return insert
endfunction

function! s:TexQuote()
    let insert = "'"
    let left = getline('.')[col('.')-2]
    if left =~# '^\(\|\s\)$'
        let insert = '`'
    elseif left ==# '('
        let insert = '`'
    elseif left ==# '\'
        let insert = "'"
    endif
    return insert
endfunction

inoremap <silent> <buffer> " <C-R>=<SID>TexQuotes()<CR>
inoremap <silent> <buffer> ' <C-R>=<SID>TexQuote()<CR>
" }}}

" Specialized fold-marker [[-,-]] {{{
setlocal foldmarker=[[-,-]]
" }}}

" Surround addition {{{
if exists('g:loaded_surround')
	" vim-surround: l for `foo' and L for ``foo''
	let b:surround_{char2nr('l')} = "`\r'"
	let b:surround_{char2nr('L')} = "``\r''"
endif
" }}}