my .vimrc

I use the text editor (g)vim with the latexsuite expansion. (for ubuntu users: it is in the repositories!) This expansion provides some shortcuts which ease the creation of LaTeX documents.

Here is my .vimrc file, most of it is easy to find in the net — actually, the only interesting part are the “let g:Tex_…” things.

In order to switch between LaTeX and pdfLaTeX, I created two shortcuts in my .bashrc which set the variable myTeXtarget.

With “\ll”, the compilation of the document (actually of the last saved version of it) is evoked together with bibtex and as far as I know also makeidx as often as needed to get all references right. “\lv” opens then a xpdf/xdvi session where the document is displayed. The nice thing is now that everytime I do a “\ll” from now on, it will refresh the pdf/dvi file and make xpdf/xdvi the topmost window (it doesn’t get the focus though). “\ld” works only with dvi and will jump to & highlight the paragraph in which the cursor is positioned.

When using dvi, Ctrl + Click on some paragraph in the dvi places the cursor in vim on the corresponding place.

I would like to thank Brett Stahlman from the vim users mailing list who helped a lot with the CompileRule. There are now two versions of it: the first one (commented out) uses the xpdf “raise” feature which does not give the focus to the xpdf window. The second version needs the program “wmctrl” installed which is then used to raise and focus the xpdf window.

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
" REQUIRED. This makes vim invoke Latex-Suite when you open a tex file.
filetype plugin on
 
" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
" set shellslash
 
" IMPORTANT: grep will sometimes skip displaying the file name if you
" search in a singe file. This will confuse Latex-Suite. Set your grep
" program to alway generate a file-name.
set grepprg=grep\ -nH\ $*
 
" make F11 "copy into clipboard"
":map <F11> "*y
 
" make F12 "paste from clipboard"
":map <F12> "*p
 
" write four spaces instead of tab
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4   " make the four spaces feel like a tab
 
" OPTIONAL: This enables automatic indentation as you type.
filetype indent on
 
" switch on syntax highlighting, use fortran free form
:let fortran_free_source=1
syntax on
 
" show cursor position all the time
set ruler
 
" line numbering
set nu
 
" wrap at word
set lbr
 
" nice colours
colorscheme default
if has("gui_running")
    colorscheme morning
else
    highlight clear SpellBad
    highlight SpellBad term=standout ctermfg=1 term=underline cterm=underline
    highlight clear SpellCap
    highlight SpellCap term=underline cterm=underline
    highlight clear SpellRare
    highlight SpellRare term=underline cterm=underline
    highlight clear SpellLocal
    highlight SpellLocal term=underline cterm=underline
endif
 
set enc=utf-8
 
" spell check
set spell
set mousemodel=popup
set spellfile=~/.spellfile.add
 
" make tab in v mode keep highlighting
vmap <tab> >gv
vmap <s-tab> <gv
 
function! SetupLatex(arg)
    if a:arg == 'pdf'
        let a:targetformat = 'pdf'
    elseif a:arg == 'dvi'
        let a:targetformat = 'dvi'
    elseif a:arg == ''
        if g:Tex_DefaultTargetFormat == 'dvi'
            let a:targetformat = 'pdf'
        else
            let a:targetformat = 'dvi'
        endif
    endif
 
    if a:targetformat == 'dvi'
        " target for latex
        let g:Tex_DefaultTargetFormat = 'dvi'
        " inverse search -- start gvim as "gvim --servername xdvi"
        "let g:Tex_CompileRule_dvi = 'latex --src -interaction nonstopmode $*'
        "let g:Tex_CompileRule_dvi = 'latex --src -interaction nonstopmode $*; if pgrep -fx "xdvi.bin -name xdvi -editor gvim --servername vim --remote +%l %f $*"; then wmctrl -a "xdvik:  $*"; fi;'
        let g:Tex_CompileRule_dvi = 'latex --src -interaction nonstopmode $*; if pgrep "xdvi.bin"; then wmctrl -a "xdvik:"; fi;'
        let g:Tex_ViewRule_dvi = 'xdvi -editor "gvim --servername vim --remote +\%l \%f" -watchfile 1 $* &'
        map \ld :execute '!xdvi -editor "gvim --servername '.v:servername.' --remote +\%l \%f" -sourceposition '.line(".").':'.col(".").expand("%").' '.expand(Tex_GetMainFileName(':r')).'.dvi >/dev/null&'<CR><CR>
    else " pdf
        let g:Tex_DefaultTargetFormat = 'pdf'
        let g:Tex_CompileRule_pdf = 'pdflatex -interaction nonstopmode $*; if pgrep -fx "xpdf -remote vimlatex $*.pdf"; then xpdf -remote vimlatex -reload && wmctrl -a "Xpdf: $*.pdf"; fi;'
        "let g:Tex_CompileRule_pdf = 'pdflatex -interaction nonstopmode $*; if pgrep -fx "xpdf -remote vimlatex $*.pdf"; then xpdf -remote vimlatex -reload -raise; fi;'
        let g:Tex_CompileRule_pdf = 'pdflatex -interaction nonstopmode $*; if pgrep -fx "xpdf -remote vimlatex $*.pdf"; then xpdf -remote vimlatex -reload && wmctrl -a "Xpdf: $*.pdf"; fi;'
        let g:Tex_ViewRule_pdf = 'xpdf -remote vimlatex'
    endif
endfunction
 
if exists("myTeXtarget")
    :call SetupLatex(myTeXtarget)
    let g:Tex_MultipleCompileFormats = 'dvi,pdf'
 
    " include cross referenced references also if they are cross referenced less
    " than two times
    let g:Tex_BibtexFlavor = 'bibtex -min-crossrefs=1'
    " let the cursor in the tex buffer if an error occured
    let g:Tex_GotoError = 0
    let g:Tex_IgnoredWarnings =
                \'Underfull'."\n".
                \'Overfull'."\n".
                \'specifier changed to'."\n".
                \'You have requested'."\n".
                \'Missing number, treated as zero.'."\n".
                \'There were undefined references'."\n".
                \'Latex Warning:'."\n".
                \'LaTeX Warning:' " float stuck
                "\'Citation %.%# undefined'
    let g:Tex_IgnoreLevel = 8
    let g:Tex_FoldedEnvironments = 'frame,verbatim,comment,eq,gather,align,figure,table,thebibliography,keywords,abstract,titlepage'
endif
 
" font
set guifont=DejaVu\ Sans\ Mono\ 8
 
" manual folding
set foldmethod=marker
"set commentstring=\ #\ %s
 
" to cycle with ctrl-N trough all labels
set iskeyword+=:
 
" remap my common typos
nmap :W :w
nmap :Q :q
 
" control-left & right arrows switch between tabs
map <c-Left> :tabp<CR>
map <c-Right> :tabn<CR>
 
" keep at least 5 lines above/below cursor
set scrolloff=5
 
" show me where i am
set cursorline
 
" completion http://vim.wikia.com/wiki/Omni_completion
set ofu=syntaxcomplete#Complete
" http://vim.wikia.com/wiki/VimTip1386
set completeopt=longest,menuone
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
inoremap <expr> <C-n> pumvisible() ? '<C-n>' :
  \ '<C-n><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
inoremap <expr> <M-,> pumvisible() ? '<C-n>' :
  \ '<C-x><C-o><C-n><C-p><C-r>=pumvisible() ? "\<lt>Down>" : ""<CR>'
" instead of control x control o: tab http://vim.wikia.com/wiki/VimTip102
function! CleverTab()
    if pumvisible()
        return "\<C-N>"
    endif
    if strpart( getline('.'), 0, col('.')-1 ) =~ '^\s*$'
        return "\<Tab>"
    elseif exists('&omnifunc') && &omnifunc != ''
        return "\<C-X>\<C-O>"
    else
        return "\<C-N>"
    endif
endfunction
inoremap <Tab> <C-R>=CleverTab()<CR>

5 Responses to “my .vimrc”

  1. ozhan says:

    Hi,
    I wonder how I could a reverse search in xpdf?

    Thanks for tips

  2. Sebastian says:

    hey there! i think i have seen only
    http://www.ctan.org/tex-archive/help/Catalogue/entries/vpe.html
    which does something like that for pdf files — but i have not really looked into it. good luck — let us know if it worked!

    [edit:]
    found another one: pdfsync
    http://itexmac.sourceforge.net/pdfsync.html
    http://tug.ctan.org/tex-archive/macros/latex/contrib/pdfsync/
    http://www.vim.org/scripts/script.php?script_id=1951
    it is made for mac but i guess one should be able to make it run also under linux…

  3. Ozhan fenerci says:

    Dear Sebastian,

    I was trying to figure out your .vimrc file. But I couldn’t understand a few things. Copy-paste of your vimrc file is not working on my system (debian-testing).
    At line 94, there is a command” let g:Tex_ViewRule_pdf = ‘xpdf -remote vimlatex’ in which I don’t understand the usage of ‘vimlatex’.

    Regards,
    Ozhan

  4. Sebastian says:

    Hi Ozhan,

    sorry for the late reply — I didn’t see your message. If you call xpdf with the option -remote, you (taken from man xpdf):
    Start/contact xpdf remote server with specified name (see the REMOTE SERVER MODE section below).

    As xpdf was broken on Ubuntu for a very long time, I have actually not used this command any more. evince updates automatically when the pdf file is changed, that might be an easier option.

    What else does not work on your system?

    Best,
    Sebastian.

  5. […] 关于vimrc文件的配置,可以参考latexsuite在sourceforge的manual,不过我感觉更实在的是这里的OVERVIEW及这个配置和这个。如果对vim-latexsuite部分安装位置不清楚的话可以dpkg -L vim-latexsuite查看。在进行一通配置后,使用gvim就可以对.tex结尾的文件特殊处理了(最惹眼的就是gvim设置成set go+=mT的情况下菜单栏和工具条多了点选项)。 […]

Leave a Reply