forked from odedniv/.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.vim
379 lines (347 loc) · 13.3 KB
/
math.vim
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
autocmd filetype tex let b:auto_save = 1
autocmd filetype tex setlocal spell spelllang=en_us
autocmd filetype tex setlocal wrap
autocmd filetype tex set iskeyword+={,}
autocmd filetype tex set iskeyword+=\
"autocmd filetype tex set iskeyword+=$
autocmd filetype tex let g:tex_fold_additional_envs = ['lem','proof','defn','thm','cor','claim','enumerate','rem','prop']
autocmd filetype tex nmap <buffer> K <leader>lv
"autocmd filetype tex nmap <buffer> <leader>inl i\leavevmode \newline <esc>
autocmd filetype tex nmap <buffer> <leader>inl ^i\medskip \medskip <esc>
autocmd filetype tex nmap <buffer> <leader>it ^i\item <esc>
autocmd filetype tex nmap <buffer> <leader>il A \\<esc>
autocmd filetype tex nmap <buffer> <leader>ll :exe ":!echo " . v:servername . " > /tmp/curserver "<CR><plug>(vimtex-compile)
autocmd filetype tex nmap <buffer> <leader>lm :exe ':!rm /tmp/builddir/' . expand('%:t:r') . '.*'<CR>
autocmd filetype tex nmap <buffer> TC <plug>(vimtex-cmd-toggle-star)
autocmd filetype tex nmap <buffer> TE <plug>(vimtex-env-toggle-star)
autocmd filetype tex nmap <buffer> TD <plug>(vimtex-delim-toggle-modifier)
autocmd filetype tex nmap <buffer> Td <plug>(vimtex-delim-toggle-modifier-reverse)
autocmd filetype tex nmap <buffer> <leader>MK ^i$<esc>$a$:s/ /\\ /g<esc>
autocmd filetype tex nmap <buffer> <leader>DM ^i\[<esc>$a\]:s/ /\\ /g<esc>
"autocmd filetype tex vnoremap <buffer> <ESC> <ESC>:w<CR>
"autocmd filetype tex inoremap <buffer> <ESC> <ESC>:w<CR>
"autocmd filetype tex nnoremap <buffer> <ESC> :w<CR><ESC>
"start compiling immediately
"autocmd BufRead filetype tex if exists exe ":!echo " . v:servername . " > /tmp/curserver " <bar> VimtexCompile
"autocmd BufRead filetype tex exec ":echo 'a'"
autocmd filetype tex nmap <buffer> <leader>sT :let $PATH='/usr/local/texlive/2019/bin/x86_64-darwin:'.$PATH<CR>
autocmd filetype tex nmap <buffer> mk a$$<esc>ha
autocmd filetype tex nmap <buffer> dm ^a\[\]<esc>hha
"sorrounds with $
autocmd filetype tex nmap <buffer> Mk ^i$<esc>$a$<esc>
autocmd filetype tex nmap <buffer> Dm ^i\[<esc>$a\]<esc>
autocmd filetype tex nmap <buffer> <leader>le :let g:tex_errors_only =1<CR><Plug>(vimtex-errors)
autocmd filetype tex nmap <buffer> <leader>lE :let g:tex_errors_only =0<CR><Plug>(vimtex-errors)
autocmd filetype tex nmap <buffer> <leader>ls :M begin\|end<CR>
autocmd filetype tex vmap <buffer> <leader>j$ "zd:call Joinmath2()<CR>"zp
autocmd filetype tex vmap <buffer> <leader>jD "zd:call Joinmath()<CR>"zp
autocmd filetype tex nmap <buffer> <leader>lm$ ysiW$
autocmd filetype tex nmap <buffer> gc <plug>(vimtex-delim-close)
function! SearchRepMath(pattern,replaceandflags)
let k=JJSyntaxSearch(a:pattern, 'texMathZone')
while k
let off=getcurpos()[2]-1
exec "s/^\\(.".'\{-'.string(off).'}\)' .a:pattern."/\1".a:replaceandflags
let k=JJSyntaxSearch(a:pattern, 'texMathZone')
endwhile
endfunction
function! JJSyntaxSearch(pattern, syntaxitem)
while search(a:pattern, 'W') > 0
for id in synstack(line("."),col("."))
if synIDattr(id,"name") =~? a:syntaxitem
return line(".")
endif
endfor
endwhile
return 0
endfunc
"remember c-.
"JJSyntaxSearch \<e\> texMathZone
"
command! -nargs=* JJSyntaxSearch call JJSyntaxSearch(<f-args>)
function! Finmath(nextstr)
while 1
"exec 'norm .'.a:nextstr
if search(a:nextstr)==0
break
endif
if searchpairpos('\(', '','\)','n')!=[0,0]
break
endif
if searchpairpos('\[', '','\]','n')!=[0,0]
break
endif
let a = getcurpos()
if count(strpart(getline('.'),0,a[2]),'$')%2==1
break
endif
endwhile
endfunction
function! NG()
call Noutmath("call grammarous#move_to_next_error(getpos('.')[1 : 2], b:grammarous_result)")
endfunction
function! Noutmath(nextstr)
let l=line('.')
let b=0
while 1
exec a:nextstr
let ll=line('.')
if ll<l
break
endif
if searchpairpos('\(', '','\)','n')!=[0,0]
continue
endif
if searchpairpos('\[', '','\]','n')!=[0,0]
continue
endif
let a = getcurpos()
if count(strpart(getline('.'),0,a[2]),'$')%2==0
break
endif
endwhile
endfunction
function! Foutmath(nextstr)
while 1
"exec 'norm .'.a:nextstr
if search(a:nextstr)==0
break
endif
if searchpairpos('\(', '','\)','n')!=[0,0]
continue
endif
if searchpairpos('\[', '','\]','n')!=[0,0]
continue
endif
let a = getcurpos()
if count(strpart(getline('.'),0,a[2]),'$')%2==0
break
endif
endwhile
endfunction
"find next aaa( in text
nmap <leader>fb :call Foutmath('\w(')<CR>l`
command! -nargs=1 Fo call Foutmath(<f-args>)
command! -nargs=1 Fi call Finmath(<f-args>)
"we replaced \l so this is for it
autocmd filetype tex nmap <buffer> ml \l
"autocmd filetype tex nunmap tsD
"autocmd filetype tex nunmap tsd
"autocmd filetype tex nunmap tsc
"autocmd filetype tex nunmap tse
autocmd filetype tex let b:surround_92 = "\\{ \r \\}"
autocmd filetype tex nmap <buffer> <leader>$ cs$\[<CR>
autocmd filetype tex nmap <buffer> <leader>[ cs$$<CR>
autocmd filetype tex nmap <buffer> <c-h>h \sb
autocmd filetype tex nmap <buffer> <c-h>d dsb
autocmd filetype tex nmap <buffer> <c-h>c csb
autocmd filetype tex nmap <buffer> <c-h>v vi{
autocmd filetype tex nmap <buffer> <c-h>( csb(
autocmd filetype tex nmap <buffer> <c-h>{ csb{
autocmd filetype tex nmap <buffer> <c-h>n \inl
"%s/\^(\(.\{-}\))/{\1}/g
"%s/_\(\d\d\)/_\\{\1\\}/g
"%s/_\([ijk'][ijk']\+\)/_{\1}/g
"
" changes { to \{
"%s/\(\w\) \(\w\)/\1 \2
" turns aa aa to aa aa
autocmd filetype tex nmap <buffer> \sb csB\
function! Joinmath2()
"split and keep $
let gg=split(@z,"\\$.\\{-}\\$\\zs")
let fs="$"
for k in gg
let pos=match(k,"\\$.\\{-}\\$")
let va=k[:pos-1] "arg regul
let vb=k[pos:] "arg $
if pos>0 && len(k)>0
let fs.= "\\text{" . va . "}"
endif
let fs.= vb[1:-2]
"if len(vb)>2
"let fs.= substitute(vb[1:-2]," ","\\\\ ","g")
"endif
endfor
let fs.="$"
let @z=fs
endfunction
function! Joinmath()
"split and keep $
let gg=split(@z,"\\$.\\{-}\\$\\zs")
let fs="$"
for k in gg
let pos=match(k,"\\$.\\{-}\\$")
let va=k[:pos-1] "arg regul
let vb=k[pos:] "arg $
if pos>0 && len(k)>0
let fs.= "\\text{" . va . "}"
endif
if len(vb)>2
let fs.= substitute(vb[1:-2]," ","\\\\ ","g")
endif
endfor
let fs.="$"
let @z=fs
endfunction
autocmd filetype tex nmap <buffer> <leader>st :set filetype=tex<CR>:w<CR>itemplate<TAB>a<esc>:VimtexToggleMain<CR>
autocmd filetype tex nmap <buffer> <leader>so :let tt=expand('%:t')<CR>:VimtexCompileOutput<CR>:exe ":MC ". tt . ":"<CR>
autocmd filetype tex imap <buffer> <M-d>s sec<c-g>
autocmd filetype tex imap <buffer> <M-d>f /<c-g>
autocmd filetype tex imap <buffer> <M-d>c cap<c-g>
autocmd filetype tex imap <buffer> <M-d>f \frac
autocmd filetype tex imap <buffer> <M-d>s sq<c-g>
autocmd filetype tex imap <buffer> <M-d>x _
autocmd filetype tex imap <buffer> <M-d>e ^
autocmd filetype tex imap <buffer> <M-d>u sum<c-g>
autocmd filetype tex imap <buffer> <M-d>i dint<c-g>
autocmd filetype tex imap <buffer> <M-e> mk<c-g>
autocmd filetype tex imap <buffer> <M-d>m mk<c-g>
autocmd filetype tex imap <buffer> <M-d>d dm<c-g>
autocmd filetype tex imap <buffer> <M-d>y \oint
autocmd filetype tex imap <buffer> <M-d>p part<c-g>
autocmd filetype tex imap <buffer> <M-d>r \root
autocmd filetype tex imap <buffer> <M-d>l lim<c-g>
"autocmd filetype tex imap <buffer> <M-d>* \<c-g>
autocmd filetype tex imap <buffer> <M-d>8 \infty
autocmd filetype tex imap <buffer> <M-d>h hat<c-g>
autocmd filetype tex imap <buffer> <M-d>^ bar<c-g>
autocmd filetype tex imap <buffer> <M-d>. **<c-g>
autocmd filetype tex imap <buffer> <M-d>v \vec
autocmd filetype tex imap <buffer> <M-d>_ \underbar
autocmd filetype tex imap <buffer> <M-d>b \overline
autocmd filetype tex imap <buffer> <M-d>( lr<c-g>
autocmd filetype tex imap <buffer> <M-d>[ lr[<c-g>
autocmd filetype tex imap <buffer> <M-d>{ lr{<c-g>
autocmd filetype tex imap <buffer> <M-d>< lr<<c-g>
autocmd filetype tex imap <buffer> <M-d><bar> lr<bar><c-g>
autocmd filetype tex imap <buffer> <M-d>+ \pm
autocmd filetype tex imap <buffer> <M-d>! \neq
autocmd filetype tex imap <buffer> <M-b>a \alpha
autocmd filetype tex imap <buffer> <M-b>b \beta
autocmd filetype tex imap <buffer> <M-b>c \chi
autocmd filetype tex imap <buffer> <M-b>d \delta
autocmd filetype tex imap <buffer> <M-b>e \epsilon
autocmd filetype tex imap <buffer> <M-b>f \phi
autocmd filetype tex imap <buffer> <M-b>g \gamma
autocmd filetype tex imap <buffer> <M-b>h \eta
autocmd filetype tex imap <buffer> <M-b>i \iota
autocmd filetype tex imap <buffer> <M-b>j \varphi
autocmd filetype tex imap <buffer> <M-b>k \kappa
autocmd filetype tex imap <buffer> <M-b>l \lambda
autocmd filetype tex imap <buffer> <M-b>m \mu
autocmd filetype tex imap <buffer> <M-b>n \nu
autocmd filetype tex imap <buffer> <M-b>o \omega
autocmd filetype tex imap <buffer> <M-b>p \pi
autocmd filetype tex imap <buffer> <M-b>q \vartheta
autocmd filetype tex imap <buffer> <M-b>r \rho
autocmd filetype tex imap <buffer> <M-b>s \sigma
autocmd filetype tex imap <buffer> <M-b>t \tau
autocmd filetype tex imap <buffer> <M-b>u \upsilon
autocmd filetype tex imap <buffer> <M-b>v \theta
autocmd filetype tex imap <buffer> <M-b>w \omega
autocmd filetype tex imap <buffer> <M-b>x \xi
autocmd filetype tex imap <buffer> <M-b>y \psi
autocmd filetype tex imap <buffer> <M-b>z \zeta
autocmd filetype tex imap <buffer> <M-S-b>d \Delta
autocmd filetype tex imap <buffer> <M-S-b>e \varepsilon
autocmd filetype tex imap <buffer> <M-S-b>f \Phi
autocmd filetype tex imap <buffer> <M-S-b>g \Gamma
autocmd filetype tex imap <buffer> <M-S-b>i \iota
autocmd filetype tex imap <buffer> <M-S-b>j \epsilon
autocmd filetype tex imap <buffer> <M-S-b>l \Lambda
autocmd filetype tex imap <buffer> <M-s-b>O \Omega
autocmd filetype tex imap <buffer> <M-S-b>p \Pi
autocmd filetype tex imap <buffer> <M-S-b>q \vartheta
autocmd filetype tex imap <buffer> <M-S-b>r \varrho
autocmd filetype tex imap <buffer> <M-S-b>s \Sigma
autocmd filetype tex imap <buffer> <M-S-b>t \varsigma
autocmd filetype tex imap <buffer> <M-S-b>v \Theta
autocmd filetype tex imap <buffer> <M-S-b>w \Omega
autocmd filetype tex imap <buffer> <M-S-b>x \Xi
autocmd filetype tex imap <buffer> <M-S-b>y \Psi
autocmd filetype tex nmap <buffer> <M-d> a<M-d>
autocmd filetype tex nmap <buffer> <M-s-d> a<M-s-d>
autocmd filetype tex nmap <buffer> <M-b> a<M-b>
autocmd filetype tex nmap <buffer> <M-s-b> a<M-s-b>
"autocmd filetype tex nmap <buffer> <M-p-0> Part
autocmd filetype tex nmap <buffer> <M-P>1 cha<c-g>
autocmd filetype tex nmap <buffer> <M-P>2 sec<c-g>
autocmd filetype tex nmap <buffer> <M-P>3 sub<c-g>
autocmd filetype tex nmap <buffer> <M-P>4 ssub<c-g>
autocmd filetype tex nmap <buffer> <M-P>5 par<c-g>
autocmd filetype tex nmap <buffer> <M-P>6 subp<c-g>
"autocmd filetype tex nmap <buffer> <d-s-p-0> part*<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-1> cha<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-2> sec<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-3> sub<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-4> ssub<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-5> par<c-g>
autocmd filetype tex nmap <buffer> <M-s-p-6> subp<c-g>
"\bind "M-p a" "layout Abstract"
"\bind "M-p S-A" "layout Author"
"\bind "M-p M-a" "layout Address"
"\bind "M-p C-a" "layout Right_Address"
"\bind "M-p b" "layout Itemize" # bulleted list
"\bind "M-p S-B" "layout Bibliography"
"\bind "M-p c" "layout LyX-Code"
"\bind "M-p S-C" "layout Comment"
"\bind "M-p d" "layout Description"
"\bind "M-p S-D" "layout Date"
"\bind "M-p e" "layout Enumerate" # numbered list
"\bind "M-p f" "layout ShortFoilhead" # Foils!!
"\bind "M-p S-F" "layout Foilhead" # Foils!!
"\bind "M-p i" "layout Itemize" # bulleted list
"\bind "M-p l" "layout List"
"\bind "M-p S-L" "layout LaTeX"
"\bind "M-p n" "layout Enumerate" # numbered list
"\bind "M-p q" "layout Quote"
"\bind "M-p S-Q" "layout Quotation"
"\bind "M-p r" "layout ShortRotatefoilhead" # Foils!!
"\bind "M-p S-R" "layout Rotatefoilhead" # Foils!!
"\bind "M-p s" "layout Standard"
"\bind "M-p t" "layout Title"
"\bind "M-p space" "drop-layouts-choice"
"\bind "M-p v" "layout Verse"
let g:vimtex_quickfix_latexlog = {
\ 'default' : 1,
\ 'ignore_filters' : ['.*Warning.*'],
\ 'general' : 1,
\ 'references' : 1,
\ 'overfull' : 1,
\ 'underfull' : 1,
\ 'font' : 1,
\ 'packages' : {
\ 'default' : 1,
\ 'general' : 1,
\ 'babel' : 1,
\ 'biblatex' : 1,
\ 'fixltx2e' : 1,
\ 'hyperref' : 1,
\ 'natbib' : 1,
\ 'scrreprt' : 1,
\ 'titlesec' : 1,
\ },
\}
"autocmd filetype tex nmap <buffer> ]] <plug>(vimtex-]])
"autocmd filetype tex nmap <buffer> ][ <plug>(vimtex-][)
"autocmd filetype tex nmap <buffer> [] <plug>(vimtex-[])
"autocmd filetype tex nmap <buffer> <nowait> [[ <plug>(vimtex-[[)
"autocmd filetype tex nmap <buffer> ]m <plug>(vimtex-]m)
"autocmd filetype tex nmap <buffer> ]M <plug>(vimtex-]M)
"autocmd filetype tex nmap <buffer> [m <plug>(vimtex-[m)
"autocmd filetype tex nmap <buffer> [M <plug>(vimtex-[M)
"*<plug>(vimtex-ac)* Commands
"*<plug>(vimtex-ic)*
"*<plug>(vimtex-ad)* Delimiters
"*<plug>(vimtex-id)*
"*<plug>(vimtex-ae)* Environments
"*<plug>(vimtex-ie)*
"*<plug>(vimtex-a$)* Inline math
"*<plug>(vimtex-i$)*
"*<plug>(vimtex-aP)* Sections
"*<plug>(vimtex-iP)*
"*<plug>(vimtex-am)* Items
"*<plug>(vimtex-im)*
"These are all text object mappings for the indicated types of objects , see
"|vimtex-text-objects| for more info.