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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
|
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
<head>
<meta charset="utf-8" />
<meta name="generator" content="pandoc" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<title>vim学习与我的配置</title>
<link rel="stylesheet" href="https://www.qin-juan-ge-zhu.top/common/CSS/pandoc.css">
<script type="text/javascript" src="https://hl.qin-juan-ge-zhu.top/myset/myhighlight.js"></script>
<script type="text/javascript" src="https://www.qin-juan-ge-zhu.top/common/script4code.js"></script>
</head>
<body>
<div class="pandoc">
<div class="main">
<p class="title">vim学习与我的配置</p>
<h1 id="vim-那是个什么-jb-东西">vim? 那是个什么 JB 东西?</h1>
<p>Enjoy coding 的你,是否时常痛恨鼠标点来点去、方向键远离字母,耽误码字?可曾詈骂手动批量重复处理的痛苦?Debug
时代码上下反复跳转,令你烦闷否?别人写的编辑器设置种种不便,是否想过有一个自己私人订制的编辑器?如果你有以上苦恼,那么 vim 将是你的绝佳选择。</p>
<p>vim 是一个文本编辑器,素有“编辑器之神”的美名,同时它也是 Linux 尤其是服务器环境下编辑文件的主要方法。</p>
<p>vim 的主要特点是分模式编辑:</p>
<table>
<thead>
<tr class="header">
<th>模式</th>
<th>说明</th>
<th>功能</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td>Normal</td>
<td>正常</td>
<td>光标移动、阅读文件</td>
</tr>
<tr class="even">
<td>Insert</td>
<td>插入</td>
<td>在当前光标位置插入内容,编辑文件</td>
</tr>
<tr class="odd">
<td>Visual</td>
<td>视觉/选择</td>
<td>选中、复制粘贴</td>
</tr>
<tr class="even">
<td>Replace</td>
<td>替换</td>
<td>替换当前光标下字符</td>
</tr>
</tbody>
</table>
<p>其关系如下:</p>
<div class="md-diagram-panel md-fences-adv-panel" lang="mermaid"><svg id="mermaidChart0" width="100%"
xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
style="max-width: 262.825px; margin: auto;" viewBox="-8 -8 262.82501220703125 235.02500915527344"
role="graphics-document document" aria-roledescription="flowchart-v2">
<style>
#mermaidChart0 {
font-family: sans-serif;
font-size: 16px;
fill: #333;
}
#mermaidChart0 .error-icon {
fill: #552222;
}
#mermaidChart0 .error-text {
fill: #552222;
stroke: #552222;
}
#mermaidChart0 .edge-thickness-normal {
stroke-width: 2px;
}
#mermaidChart0 .edge-thickness-thick {
stroke-width: 3.5px;
}
#mermaidChart0 .edge-pattern-solid {
stroke-dasharray: 0;
}
#mermaidChart0 .edge-pattern-dashed {
stroke-dasharray: 3;
}
#mermaidChart0 .edge-pattern-dotted {
stroke-dasharray: 2;
}
#mermaidChart0 .marker {
fill: #333333;
stroke: #333333;
}
#mermaidChart0 .marker.cross {
stroke: #333333;
}
#mermaidChart0 svg {
font-family: sans-serif;
font-size: 16px;
}
#mermaidChart0 .label {
font-family: sans-serif;
color: #333;
}
#mermaidChart0 .cluster-label text {
fill: #333;
}
#mermaidChart0 .cluster-label span,
#mermaidChart0 p {
color: #333;
}
#mermaidChart0 .label text,
#mermaidChart0 span,
#mermaidChart0 p {
fill: #333;
color: #333;
}
#mermaidChart0 .node rect,
#mermaidChart0 .node circle,
#mermaidChart0 .node ellipse,
#mermaidChart0 .node polygon,
#mermaidChart0 .node path {
fill: #ECECFF;
stroke: #9370DB;
stroke-width: 1px;
}
#mermaidChart0 .flowchart-label text {
text-anchor: middle;
}
#mermaidChart0 .node .label {
text-align: center;
}
#mermaidChart0 .node.clickable {
cursor: pointer;
}
#mermaidChart0 .arrowheadPath {
fill: #333333;
}
#mermaidChart0 .edgePath .path {
stroke: #333333;
stroke-width: 2.0px;
}
#mermaidChart0 .flowchart-link {
stroke: #333333;
fill: none;
}
#mermaidChart0 .edgeLabel {
background-color: #e8e8e8;
text-align: center;
}
#mermaidChart0 .edgeLabel rect {
opacity: 0.5;
background-color: #e8e8e8;
fill: #e8e8e8;
}
#mermaidChart0 .labelBkg {
background-color: rgba(232, 232, 232, 0.5);
}
#mermaidChart0 .cluster rect {
fill: #ffffde;
stroke: #aaaa33;
stroke-width: 1px;
}
#mermaidChart0 .cluster text {
fill: #333;
}
#mermaidChart0 .cluster span,
#mermaidChart0 p {
color: #333;
}
#mermaidChart0 div.mermaidTooltip {
position: absolute;
text-align: center;
max-width: 200px;
padding: 2px;
font-family: sans-serif;
font-size: 12px;
background: hsl(80, 100%, 96.2745098039%);
border: 1px solid #aaaa33;
border-radius: 2px;
pointer-events: none;
z-index: 100;
}
#mermaidChart0 .flowchartTitleText {
text-anchor: middle;
font-size: 18px;
fill: #333;
}
#mermaidChart0 :root {
--mermaid-alt-font-family: sans-serif;
}
</style>
<g>
<marker id="mermaidChart0_flowchart-pointEnd" class="marker flowchart" viewBox="0 0 10 10"
refX="6" refY="5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12"
orient="auto">
<path d="M 0 0 L 10 5 L 0 10 z" class="arrowMarkerPath"
style="stroke-width: 1; stroke-dasharray: 1, 0;"></path>
</marker>
<marker id="mermaidChart0_flowchart-pointStart" class="marker flowchart" viewBox="0 0 10 10"
refX="4.5" refY="5" markerUnits="userSpaceOnUse" markerWidth="12" markerHeight="12"
orient="auto">
<path d="M 0 5 L 10 10 L 10 0 z" class="arrowMarkerPath"
style="stroke-width: 1; stroke-dasharray: 1, 0;"></path>
</marker>
<marker id="mermaidChart0_flowchart-circleEnd" class="marker flowchart" viewBox="0 0 10 10"
refX="11" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11"
orient="auto">
<circle cx="5" cy="5" r="5" class="arrowMarkerPath"
style="stroke-width: 1; stroke-dasharray: 1, 0;"></circle>
</marker>
<marker id="mermaidChart0_flowchart-circleStart" class="marker flowchart" viewBox="0 0 10 10"
refX="-1" refY="5" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11"
orient="auto">
<circle cx="5" cy="5" r="5" class="arrowMarkerPath"
style="stroke-width: 1; stroke-dasharray: 1, 0;"></circle>
</marker>
<marker id="mermaidChart0_flowchart-crossEnd" class="marker cross flowchart" viewBox="0 0 11 11"
refX="12" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11" markerHeight="11"
orient="auto">
<path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath"
style="stroke-width: 2; stroke-dasharray: 1, 0;"></path>
</marker>
<marker id="mermaidChart0_flowchart-crossStart" class="marker cross flowchart"
viewBox="0 0 11 11" refX="-1" refY="5.2" markerUnits="userSpaceOnUse" markerWidth="11"
markerHeight="11" orient="auto">
<path d="M 1,1 l 9,9 M 10,1 l -9,9" class="arrowMarkerPath"
style="stroke-width: 2; stroke-dasharray: 1, 0;"></path>
</marker>
<g class="root">
<g class="clusters"></g>
<g class="edgePaths">
<path d="M48.358,89.675L97.363,9.837L122.363,9.837L147.363,9.837L175.048,14.286"
id="L-N-I-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-I"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
<path d="M71.02,89.675L97.363,74.675L122.363,74.675L147.363,74.675L174.744,90.003"
id="L-N-V-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-V"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
<path d="M58.314,129.35L97.363,164.35L122.363,164.35L147.363,164.35L169.533,176.761"
id="L-N-R-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-N LE-R"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
<path d="M180.281,36.247L147.363,54.675L122.363,54.675L97.363,54.675L62.26,86.138"
id="L-I-N-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-I LE-N"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
<path d="M179.369,126.433L147.363,144.35L122.363,144.35L97.363,144.35L75.625,131.973"
id="L-V-N-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-V LE-N"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
<path d="M172.363,205.17L147.363,209.187L122.363,209.187L97.363,209.187L51.13,133.867"
id="L-R-N-0"
class=" edge-thickness-normal edge-pattern-solid flowchart-link LS-R LE-N"
style="fill:none;" marker-end="url(#mermaidChart0_flowchart-pointEnd)"></path>
</g>
<g class="edgeLabels">
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
<g class="edgeLabel">
<g class="label" transform="translate(0, 0)">
<foreignObject width="0" height="0">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="edgeLabel"></span></div>
</foreignObject>
</g>
</g>
</g>
<g class="nodes">
<g class="node default default flowchart-label" id="flowchart-N-0"
transform="translate(36.181251525878906, 109.51249885559082)">
<rect class="basic label-container" style="" rx="5" ry="5" x="-36.18124961853027"
y="-19.83750057220459" width="72.36249923706055" height="39.67500114440918">
</rect>
<g class="label" style=""
transform="translate(-28.681249618530273, -12.33750057220459)">
<rect></rect>
<foreignObject width="57.36249923706055" height="24.67500114440918">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="nodeLabel">Normal</span></div>
</foreignObject>
</g>
</g>
<g class="node default default flowchart-label" id="flowchart-I-1"
transform="translate(209.59375381469727, 19.837499618530273)">
<rect class="basic label-container" style="" rx="5" ry="5" x="-29.3125"
y="-19.83750057220459" width="58.625" height="39.67500114440918"></rect>
<g class="label" style="" transform="translate(-21.8125, -12.33750057220459)">
<rect></rect>
<foreignObject width="43.625" height="24.67500114440918">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="nodeLabel">Insert</span></div>
</foreignObject>
</g>
</g>
<g class="node default default flowchart-label" id="flowchart-V-3"
transform="translate(209.59375381469727, 109.51249885559082)">
<rect class="basic label-container" style="" rx="5" ry="5" x="-30.225000381469727"
y="-19.83750057220459" width="60.45000076293945" height="39.67500114440918">
</rect>
<g class="label" style=""
transform="translate(-22.725000381469727, -12.33750057220459)">
<rect></rect>
<foreignObject width="45.45000076293945" height="24.67500114440918">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="nodeLabel">Visual</span></div>
</foreignObject>
</g>
</g>
<g class="node default default flowchart-label" id="flowchart-R-5"
transform="translate(209.59375381469727, 199.18749809265137)">
<rect class="basic label-container" style="" rx="5" ry="5" x="-37.23125076293945"
y="-19.83750057220459" width="74.4625015258789" height="39.67500114440918">
</rect>
<g class="label" style=""
transform="translate(-29.731250762939453, -12.33750057220459)">
<rect></rect>
<foreignObject width="59.462501525878906" height="24.67500114440918">
<div xmlns="http://www.w3.org/1999/xhtml"
style="display: inline-block; white-space: nowrap;"><span
class="nodeLabel">Replace</span></div>
</foreignObject>
</g>
</g>
</g>
</g>
</g>
</svg></div>
<h1 id="我的-vim-学习路线">我的 vim 学习路线</h1>
<p>不幸的是 Vim 的学习曲线确实相当陡峭,最开始你会觉得非常不适应,但一旦熬过了初始阶段,你会爱上 Vim。以我而言,现在离开了 vim 的模式几乎已经快不会写材料了,前几天交作业要求
word,我保存文件居然不是<kbd>Ctrl+s</kbd>,而是顺手来了个<kbd>:wq</kbd>。</p>
<p>我的 vim 学习路线如下:</p>
<ul>
<li>环境:虚拟机 Ubuntu22.04 LTS 环境,vim。也可以使用 windows 下的 gvim/neovim 或 gitbash 自带 vim 等。</li>
<li>首先,阅读和观看 MIT 的<code>Missing Semister</code>中关于 vim 的<a
href="https://missing.csail.mit.edu/2020/editors/">课程</a>。<strong>消失的学期其他课程也非常不错。要是我刚上大学就知道有这个学期该多好!</strong>
</li>
<li>而后,在网上玩<a href="https://vim-adventures.com/">Vim
Adventures</a>,多玩几遍,直到熟悉其所有键位。<del><strong>“家贫,无从致游戏以玩”</strong>,谁要是有这个游戏全版,记得 v 我一份!</del></li>
<li>同时,在命令行中学<code>vimtutor</code>,这是 vim 自带的基础官方教程,对于基础使用方法介绍非常完整。
<ul>
<li>系统如果是中文则该教程是中文,否则为英文。</li>
<li>使用方法为在命令行中输入<kbd>vimtutor</kbd>并回车。学习过程中尽量不要退出,因为教程不会保存本次做过的操作,下次再进来是个新的。</li>
<li>第一次学会慢一些,一小时左右,一共 7 章若干节,一节一个技能,每一章有一个总结。</li>
</ul>
</li>
<li>用了 vim,你难道不觉得键盘上的 Esc 放那么远简直是反人类吗?没错,我也这么觉得。于是想到自己做<a
href="https://www.qin-juan-ge-zhu.top/code/linux/keymap.html">键盘映射</a>。</li>
</ul>
<p>想了解其他信息,可以参考 CSDiy 的<a href="https://csdiy.wiki/%E5%BF%85%E5%AD%A6%E5%B7%A5%E5%85%B7/Vim/">vim
指南</a>。当然,众所周知,学习工具的核心在于使用,用起来逢山开路遇水搭桥,才最具效率和效果,<em>isn’t it?</em> 现代的我们,大多数情况的代码都有 IDE,但 vim
的分模式编辑和高度定制化一定会帮我们在 Coding 之路上快马加鞭。在你的各种 IDE 里安装 vim 插件,练起来,享受 All in One 的乐趣吧!</p>
<h1 id="vim-手动编译安装">vim 手动编译安装</h1>
<p>vim 在许多 Linux 发行版都有预装,即使没有预装的也都可以下载到安装包进行安装。但是这里边有几个问题:</p>
<ul>
<li>很多 vim 版本不支持 python/python2/rust/perl/lua 等语言编写的插件。
<ul>
<li>是否支持某功能,在命令行运行<code>vim --version</code>或在 vim
内运行<code>:version</code>命令即可查看,带有<code>+</code>号的表示支持,<code>-</code>号表示不支持。</li>
<li>语言后边带有<code>dyn</code>的(如<code>+python3/dyn</code>)表示支持动态链接,否则表示仅静态链接。</li>
</ul>
</li>
<li>不论何种 Linux 发行版,使用的 vim 版本都略微比发行时间旧一些以保证稳定性;但有时追求新功能的话需要最新版,甚至网上找不到你需要的版本的安装包。</li>
</ul>
<p>因而,我们有时会需要自己手动编译安装 vim。即以我而言,为了在 vim 上使用 GitHub Copilot 插件,根据插件文档要求,我不得不手动编译 vim。下面是我的编译过程。当前系统为
Ubuntu22.04 LTS。编译过程中主要参考以下几篇文章,在此一并致谢:</p>
<ul>
<li><a href="https://richrose.dev/posts/linux/vim/vim-compile/">Compiling Vim</a></li>
<li><a href="https://blog.csdn.net/MHSMIE/article/details/112005119">vim 使用原码升级到最新版本</a></li>
<li><a href="https://zhuanlan.zhihu.com/p/111592292">VIM 学习笔记 编译 Vim 支持 Python3</a></li>
</ul>
<h2 id="清理干净">清理干净</h2>
<p>下载的第一步当然是卸载当前系统具有的 vim 了。除此之外,由于 Python2 过于老旧,我选择不支持 Python2 仅支持 Python3 的 vim,因此也将 Python2 卸载。</p>
<pre><code>sudo apt autoremove vim rvim gvim vim-runtime
sudo apt autoremove python2*</code></pre>
<h2 id="做好准备">做好准备</h2>
<p>为了编译能够支持 python3/rust/perl/lua 等语言的 vim,我们需要安装一些包。</p>
<pre><code>sudo apt install -y git \
libatk1.0-dev \
libcairo2-dev \
liblua5.1-0-dev \
libncurses5-dev \
libperl-dev \
libx11-dev \
libxpm-dev \
libxt-dev \
lua5.1 \
python3-dev \
ruby-dev \
# libgtk2.0-dev</code></pre>
<p>由于我的编译在服务器上运行,主要运行环境为命令行,不需要 gtk2 等图形界面的支持,因而将安装 gtk 的那一行注释掉了。在编译带有 gtk2.0 的 vim 时似乎会遇到问题:vim
源码截至目前版本(v9.0.1854)采用的 gtk 代码中的<code>struct _GTimeVal</code>已经被弃用,gcc
要求改用<code>struct _GDateTime</code>,因此编译时会报错,而且陷入死循环,编译不会终止,只能<kbd>Ctrl+c</kbd>杀死进程。我尚不知道如何解决。这也是我放弃支持
gtk 的原因之一。</p>
<h2 id="下载源码">下载源码</h2>
<p>vim 源码可以通过其<a href="https://github.com/vim/vim">GitHub 仓库</a>下载,也可以在其<a
href="https://www.vim.org/download.php">官网</a>下载。我选择了前者。</p>
<pre><code>git clone https://github.com/vim/vim
# 后续处理过程都在源码目录下的src目录内进行,因而切换过去
cd vim/src
# 如果此前自己编译安装过vim,需要先卸载自己的安装并清理上次的编译文件,否则会持续报错
sudo make uninstall
sudo make distclean</code></pre>
<h2 id="开干">开干!</h2>
<h3 id="configure">configure</h3>
<p>vim
的编译过程中,需要先运行<code>configure</code>脚本,该脚本会检查当前系统的环境,并以参数形式接收你需要哪些功能。可以通过<code>./configure --help</code>查看所有可选参数及其功能说明。我选择的参数如下:
</p>
<pre><code>sudo ./configure\
--with-features=huge \
--enable-multibyte \
--enable-rubyinterp=dynamic \
--with-ruby-command=/usr/bin/ruby \
--enable-luainterp\
--enable-python3interp=dynamic \
--with-python3-command=/usr/bin/python3.10 \
--with-python3-config-dir=/usr/lib/python3.10/config-3.10-x86_64-linux-gnu \
--enable-perlinterp=dynamic \
--enable-largefile \
--enable-cscope \
--with-compiledby="An Ordinary Communist weunite1848@gmail.com" \
--enable-fail-if-missing \
--prefix=/usr</code></pre>
<p>对以上选择的参数做一简要说明:</p>
<ul>
<li><code>--with-features=huge</code>:支持最多的功能</li>
<li><code>--enable-multibyte</code>:支持多字节字符(比如中文!!!)</li>
<li><code>--enable-rubyinterp=dynamic</code>:支持 ruby 插件,动态链接</li>
<li><code>--with-ruby-command=/usr/bin/ruby</code>或<code>--with-python3-command=/usr/bin/python3</code>等,指定
vim 使用的这些语言解释器的位置</li>
<li><code>--with-python3-config-dir=/usr/lib/python3.10/config-3.10-x86_64-linux-gnu</code>,指定 python3 的
config 文件位置。
<ul>
<li>该文件在不同系统上的位置不同,可以通过命令行运行<code>python3-config --configdir</code>查看。</li>
</ul>
</li>
<li><code>--enable-largefile</code>:支持大文件</li>
<li><code>--enable-cscope</code>:支持 cscope</li>
<li><code>--with-compiledby</code>:说明编译者。该信息在编译结束之后会在 vim 首页、帮助页面及版本信息中显示,也就是你的名字与此次编译的 vim 版本永远绑定了。
</li>
<li><code>--enable-fail-if-missing</code>:如果缺少某些功能,编译过程会终止,而不是继续编译。强烈推荐加上!否则遇到编译错误还继续编译,只会得到不符合需求的 vim。
</li>
<li><code>--prefix=/usr</code>:指定安装位置。默认为<code>/usr/local</code>,但我选择了<code>/usr</code>。</li>
</ul>
<p>除此之外还有一些参数,如<code>--enable-gui=gtk2</code>/<code>--enable-gtk2-check</code>/<code>--enable-fontset</code>等,可以根据自己的需求选择。
</p>
<h3 id="编译安装">编译安装</h3>
<p>编译安装过程简单到无以复加,就几句话的事。</p>
<pre><code># 编译
sudo make
# 安装
sudo make install</code></pre>
<p>安装过程中可能会出现报错,如部分文件(<code>ex</code>/<code>view</code>等)已经存在,删掉该文件再重新运行命令安装便是。</p>
<p>安装完成后,可以在命令行中运行<code>vim --version</code>查看 vim 的版本信息,确认是否支持你需要的功能。</p>
<p>最后,将我的<a href="https://file.qin-juan-ge-zhu.top/compile_vim.sh">编译安装脚本</a>奉上,供参考。</p>
<h1 id="我的-vim-配置">我的 vim 配置</h1>
<p>网上一般的教程都说 vim 的默认配置文件为<code>~/.vimrc</code>。这当然是不错的,但是有一个巨大的问题:家目录是随着用户而不同的,这会导致我们以当前普通用户打开 vim 编辑文件与以
root 用户使用 vim 的观感完全不一致,就很烦。</p>
<p>通过查看<kbd>vim –version</kbd>的输出,可以发现,vim 的配置文件有几层,其中“系统 vimrc
文件”被放置在<code>$VIM/vimrc</code>,而<code>$VIM</code>为<code>/etc/vim</code>。因此,我们可以将 vim
的配置文件放置在<code>/etc/vim</code>下,这样不论是普通用户还是 root
用户,都会使用这份文件,保证观感一致。另外,由于该文件位置较远,我选择在<code>~/useful</code>下创建软链接,方便使用。</p>
<p>除此之外,出于同样的目的(保证当前用户与 root 用户观感一致),建议将插件也指定一个专门的绝对路径。我放在了<code>/home/player/useful/bundle</code>。</p>
<pre><code># 创建软链接
# 我习惯把有用的文件放在~/useful下
mkdir useful
cd useful
# 创建软链接
sudo ln -s /etc/vim /home/player/useful/vim
# 插件存放位置
mkdir bundle</code></pre>
<h2 id="设置">设置</h2>
<p>这里原本记录着我的旧版 vim 配置,但随着<a href="https://www.qin-juan-ge-zhu.top/code/linux/httpmyserver.html">http
浏览服务器文件</a>的完成,再保留旧版然后每隔三四个月更新一次,对于我这种没事就折腾的人来说说,就显得不那么必要了。因此,这里只简单说一下。</p>
<p>配置的整体结构如下:</p>
<pre><code>/etc/vim
├── vimrc # vim配置文件,负责引入不同的配置模块
├── vimrc_origin # 原有配置脚本备份
├── vimrcs # 我的配置文件夹,里边是不同的配置模块
│ ├── autocmd.vim
│ ├── codecmd.vim
│ ├── keybind.vim
│ ├── match.vim
│ ├── myset.vim
│ ├── plugs.vim
│ └── statusline.vim
├── vimrc.tiny # 原有脚本,无用
└── vimscript.vim # 原有脚本,无用</code></pre>
<p>我直接把我服务器上的配置文件<a href="https://file.qin-juan-ge-zhu.top/useful/vim/">放在这里</a>,以供查看。</p>
<p class="time">2023.7.5<br>2023.9.6<br>2024.1.3</p>
<script src="https://www.qin-juan-ge-zhu.top/common/js/comment.js"></script>
</div>
</div>
</body>
</html>
|