自定义UltiSnips片段

在学习过程中,需要输入太多的数学符号,这就需要大量的记忆,然而要想实现在课堂上用电脑随时记录老师的讲义,那需要较快的输入速度,如果因为查找一个符号的LaTeX的表示,则必然会耽误时间,这就是本文存在的意义。这里我使用UltiSnips,将常用的一些数学符号以中文拼音的方式标记为UltiSnips自动触发的关键字,由于目前涉及内容不多,所以仅做出如下一些约定:

2023年04月22日星期六多云北京市北京师范大学

关于UltiSnips的使用,可以参考文章:

  1. UltiSnips 让 Vim 飞起来

  2. VIM 代码片段插件 ultisnips 使用教程

  3. UltiSnips使用

  4. vim下使用UltiSnips

自定义latex 片段

2023年04月22日星期六多云北京市北京师范大学
~/.vim/bundle/vim-snippets/UltiSnips/tex.snipptes
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

# latex-suite: math input snippets:

snippet bing "\cup" Ai
\cup
endsnippet

snippet jiao "\cap" Ai
\cap
endsnippet

snippet baohanyu "\subset" Ai
\subset
endsnippet

snippet baohanyu1 "\subseteq" Ai
\subseteq
endsnippet

snippet zhenbaohanyu "\subsetneq" Ai
\subsetneq
endsnippet

snippet baohan "\supset" Ai
\supset
endsnippet

snippet baohan1 "\supseteq" Ai
\supseteq
endsnippet

snippet zhenbaohan "\supsetneq" Ai
\supsetneq
endsnippet

snippet hengdengyu "\equiv" Ai
\equiv
endsnippet

snippet shuyu "\in" Ai
\in
endsnippet

snippet yuanxiaoyu "\ll" Ai
\ll
endsnippet

snippet yuandayu "\gg" Ai
\gg
endsnippet

snippet zhengbiyu "\proto" Ai
\proto
endsnippet

snippet yuedengyu "\approx" Ai
\approx
endsnippet

snippet dengyu "\eq" Ai
\eq
endsnippet

snippet budengyua "\neq" Ai
\neq
endsnippet

snippet cheng "\times" Ai
\times
endsnippet

snippet chuyi "\div" Ai
\div
endsnippet

snippet cunzai "\exists" Ai
\exists
endsnippet

snippet renyi "\forall" Ai
\forall
endsnippet

snippet d "\mathrm{d}" i
\mathrm{d}
endsnippet

snippet xiaoyudengyu "\leqslant" Ai
\leqslant
endsnippet

snippet dayudengyu "\geqslant" Ai
\geqslant
endsnippet

自定义通用片段

~/.vim/bundle/vim-snippets/UltiSnips/all.snipptes 2022年11月01日
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
# This file contains snippets that are always defined. I personally
# have snippets for signatures and often needed texts

# sligthly lower priority than everything else since specialized versions
# should overwrite. The user needs to adjust her priority in her snippets to
# ~-55 so that other filetypes will still overwrite.
priority -60

##############
# NICE BOXES #
##############
global !p
from vimsnippets import foldmarker, make_box, get_comment_format
LOREM = """
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod \
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At \
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, \
no sea takimata sanctus est Lorem ipsum dolor sit amet.
"""
endglobal

snippet box "A nice box with the current comment symbol" b
`!p
box = make_box(len(t[1]))
snip.rv = box[0]
snip += box[1]
`${1:${VISUAL:content}}`!p
box = make_box(len(t[1]))
snip.rv = box[2]
snip += box[3]`
$0
endsnippet

snippet bbox "A nice box over the full width" b
`!p
if not snip.c:
width = int(vim.eval("&textwidth - (virtcol('.') == 1 ? 0 : virtcol('.'))")) or 71
box = make_box(len(t[1]), width)
snip.rv = box[0]
snip += box[1]
`${1:${VISUAL:content}}`!p
box = make_box(len(t[1]), width)
snip.rv = box[2]
snip += box[3]`
$0
endsnippet

snippet fold "Insert a vim fold marker" b
`!p snip.rv = get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]`${2:1} `!p snip.rv = get_comment_format()[2]`
endsnippet

snippet foldc "Insert a vim fold close marker" b
`!p snip.rv = get_comment_format()[0]` ${2:1}`!p snip.rv = foldmarker()[1]` `!p snip.rv = get_comment_format()[2]`
endsnippet

snippet foldp "Insert a vim fold marker pair" b
`!p snip.rv = get_comment_format()[0]` ${1:Fold description} `!p snip.rv = foldmarker()[0]` `!p snip.rv = get_comment_format()[2]`
${2:${VISUAL:Content}}
`!p snip.rv = get_comment_format()[0]` `!p snip.rv = foldmarker()[1]` $1 `!p snip.rv = get_comment_format()[2]`
endsnippet

##########################
# LOREM IPSUM GENERATORS #
##########################
snippet "lorem(([1-4])?[0-9])?" "Lorem Ipsum" r
`!p snip.rv = " ".join(LOREM.split()[:int(match.group(1))]) if match.group(1) else LOREM`
endsnippet

##########################
# VIM MODELINE GENERATOR #
##########################
# See advice on `:help 'tabstop'` for why these values are set. Uses second
# modeline form ('set') to work in languages with comment terminators
# (/* like C */).
snippet modeline "Vim modeline"
vim`!v ':set '. (&expandtab ? printf('et sw=%i ts=%i', &sw, &ts) : printf('noet sts=%i sw=%i ts=%i', &sts, &sw, &ts)) . (&tw ? ' tw='. &tw : '') . ':'`
endsnippet

#########
# DATES #
#########
snippet date "YYYY-MM-DD" w
`!v strftime("%Y-%m-%d")`
endsnippet

snippet ddate "Month DD, YYYY" w
`!v strftime("%b %d, %Y")`
endsnippet

snippet diso "ISO format datetime" w
`!v strftime("%Y-%m-%d %H:%M:%S%z")`
endsnippet

snippet time "hh:mm" w
`!v strftime("%H:%M")`
endsnippet

snippet datetime "YYYY-MM-DD hh:mm" w
`!v strftime("%Y-%m-%d %H:%M")`
endsnippet

snippet todo "TODO comment" bw
`!p snip.rv=get_comment_format()[0]` ${2:TODO}: $0${3: <${4:`!v strftime('%d-%m-%y')`}${5:, `!v g:snips_author`}>} `!p snip.rv=get_comment_format()[2]`
endsnippet

#########
# China DATES #
#########
snippet cdate "YYYY年MM月DD日" w
`!v strftime("%Y年%m月%d日")`
endsnippet

snippet cddate "Month DD, YYYY" w
`!v strftime("%m月%d日, %Y年")`
endsnippet

snippet cdiso "ISO format datetime" w
`!v strftime("%Y年%m月%d日 %H:%M:%S%z")`
endsnippet

snippet ctime "hh:mm" w
`!v strftime("%H时%M分%S秒")`
endsnippet

snippet cdatetime "YYYY-MM-DD hh:mm" w
`!v strftime("%Y年%m月%d日 %H时%M分%S秒%z时区")`
endsnippet

snippet ctodo "TODO comment" bw
`!p snip.rv=get_comment_format()[0]` ${2:TODO}: $0${3: <${4:`!v strftime('%y年%m月%d日')`}${5:, `!v g:snips_author`}>} `!p snip.rv=get_comment_format()[2]`
endsnippet
##########
# Misc #
##########
snippet uuid "Random UUID" w
`!p if not snip.c: import uuid; snip.rv = str(uuid.uuid4())`
endsnippet

# vim:ft=snippets:
#
############
# Weather #
############
snippet weather "Weather" im
`weather -w`
endsnippet
snippet city "City" im
`weather -c`
endsnippet
snippet address "Address" im
`weather -a`
endsnippet
snippet dcw "date city weather" im
`weather -dcw`
endsnippet
snippet dwc "date city weather" im
`weather -dwc`
endsnippet
snippet wcd "date city weather" im
`weather -wcd`
endsnippet
snippet wdc "date city weather" im
`weather -wdc`
endsnippet
snippet cwd "date city weather" im
`weather -cwd`
endsnippet
snippet cdw "date city weather" im
`weather -cdw`
endsnippet
snippet dwca "date city weather" im
`weather`
endsnippet

由于存在特殊字符所以采用反斜杠的方式引用代码
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
####################
# Hexo Next theme #
####################

snippet code "code" im
<!-- code [title] [lang:language] [url] [link text] [additional options] -->
{% code ${1:title} lang:${2:language} %}
${3:}
{% endcode %}
endsnippet

snippet codeblock "codeblock" im
<!-- codeblock [title] [lang:language] [url] [link text] [additional options] -->
{% code ${1:title} lang:${2:language} %}
${3:}
{% endcodeblock %}
endsnippet

snippet ``` "```" im
<!-- \`\`\`[language] [title] [url] [link text] [additional options] -->
\`\`\`${1:language} ${2:title}
${3:}
\`\`\`
endsnippet

snippet note "note" im
<!-- default/primary/success/info/warning/danger -->
{% note ${1:default} %}
${2:}
{% endnote %}
endsnippet

snippet tabs "tabs" im
<!-- tabs Unique name , [index] -->
<!-- tab [Tab caption] [@icon] -->
{% tabs ${1:UniqueName} %}
<!-- tab ${2:tabcaption} -->
${3:}
<!-- endtab -->
{% endtabs %}
endsnippet

snippet tab "tab" im
<!-- tab ${1:tabcaption} -->
${2:}
<!-- endtab -->
endsnippet

snippet label "label" im
<!-- [class]:default/primary/success/info/warning/danger -->
{% label ${1:class}@${2:text} %}
endsnippet

snippet cq "centerquote" im
{% centerquote %}
${1:}
{% endcenterquote %}
endsnippet

snippet video "video" im
<!-- url: https://example.com/sample.mp4 -->
<!-- url: /path/to/your/video.mp4 -->
{% video ${1:url} %}
endsnippet

snippet gp "grouppicture" im
{% grouppicture ${1:number}-${2:layout} %}
![](${3:yourpicture})
{% endgrouppicture %}
endsnippet

snippet pdf "pdf file" im
<!-- url: https://example.com/sample.pdf -->
<!-- url: /path/to/your/video.pdf -->
{% pdf ${1:url} ${2:height}px %}
endsnippet