和许多前辈一样,我的文本编辑器之旅始于运行vim,很快便感到迷茫,然后又无法退出 vim,最后只好重启电脑。就这样,我最初成为了 vimemacs的用户——主要是因为nano当时 vim 还不为人所知。最终,我学会了 vim 的最低使用方法,仅够进行基本的文本编辑。
真正让我改变对 Vim 看法的,是花了一些时间去学习它。Vim 的学习曲线非常陡峭。在 Linux 上工作多年之后,我大约在 2009 年才花了相当多的时间学习 Vim,并根据自己的喜好进行定制。我可以毫不犹豫地说,我最终非常喜欢 Vim——它确实提高了我的工作效率。它功能强大,用途广泛——更重要的是,我有没有说过我喜欢它?
以前,我的 vim 配置是一堆杂乱的配置文件和一堆插件,它们被堆放在一个目录中,直到最后才逐渐恢复到我想要的状态。当时 vim 还没有完善的插件包管理工具,所以不得不这么做。后来Pathogen出现了,我抓住机会更好地组织 vim 文件。虽然 Pathogen 简化了 vim 文件和插件的组织管理,但它没有内置追踪多个插件源随时间变化的方法。
当时我已经在使用git并熟悉了这个相对较新的git submodules功能。我觉得可以使用 git submodules 来有效地管理单个插件。我四处寻找,看看是否有人已经想到了这一点。尽管我确信其他人可能已经想到了——据我所知——但当时没有人公开分享过类似的设置。所以我使用了 submodules 来实现——这对我来说只是个小小炫耀。我之前版本的 vim 配置文件已经不存在了。不过,git 仓库里有一个存档的、稍晚一些的版本。
从那时起,我维护 vim 设置最明显的变化就是切换到vim-plug插件管理。优秀的 vim-plug 免除了我处理 git 子模块的麻烦,让整个过程变得非常轻松。
以下部分将描述我正在使用的 vim 配置。我也会尽量在以后更新这篇文章,希望它能对某些人有所帮助——就像它帮助我了解其他人的做法一样。
Vim 有点像这样。它有一个Insert Mode输入文本(例如,打字)到编辑器的地方。它有一个Visual Mode选择文本部分的地方,这样你就可以直观地跟踪你正在对哪个文本部分进行操作(例如,复制选定的文本)。然后还有一个Normal Mode执行其他所有操作的地方,例如移动和操作文本(例如,剪切、复制、粘贴、删除等)。
Vim 中的Abuffer是内存中的编辑空间。您可以在那里打开一个文件,也可以稍后保存到文件中,或者直接丢弃它。一个 Vim 实例中可以打开多个缓冲区。
Vim 中的Awindow指的是缓冲区的视图。您可以拥有一个包含单个缓冲区的窗口,也可以在同一个缓冲区中拥有多个视图(例如,水平/垂直屏幕分割,或作为独立窗口)。例如,您可以将屏幕区域分割成两个窗口,并分别查看已打开文件的两个不同位置。请记住,这里提到的“窗口”指的是 Vim 窗口(通常以全屏或分屏区域显示),不一定是您习惯使用的图形窗口。
Vim 中的Atab page是组织 Vim 窗口的一种方式。这意味着每个标签页可以包含多个 Vim 窗口(例如,拆分窗口)。因此,你也可以在多个标签页中查看同一个缓冲区。
Vim 可以通过插件进行扩展。你可以使用插件(即用其他编程语言编写的程序vimscript)来添加 Vim 中未内置的特性/功能。下面你将看到我正在使用的插件。
总结一下这些关键概念:
Vim 有多种模式
使用 Vim 编辑就像编写文本
您可以定义自己的快捷方式
Vimbuffers是不同的编辑空间,而 vimtab pages不是
Vim 可通过插件进行扩展
解释我的配置
这些都是围绕 Fedora 系列 Linux 发行版(即包括 Fedora*、CentOS 和 Red Hat Enterprise Linux)中的默认 vim 安装环境构建的,因为这些是我通常的工作环境。
我的 .vimrc 从一些基本设置开始。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
我知道“制表符 vs 空格”之争会多么两极分化。因此,我不会参与其中。我一开始是“制表符”阵营的,但我尽可能地使用空格代替制表符,主要是为了在不同环境下获得相对一致的视觉体验。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
使用 Vim 时,您无需使用鼠标——事实上,我们不建议这样做。但如果您想做一些实用的事情,比如在进行目视检查时以自己的速度滚动,然后点击跳转到某个位置,那么您可以这样做。虽然我喜欢使用 Vim,但我并不反对只使用键盘。有时,在使用 Vim 时,加入鼠标——或者更准确地说,不让鼠标/触摸板变得毫无用处——会很有帮助。这就是我也启用鼠标的原因。
Vim 也有一个 GUI 版本,通常称为gvim。它带有类似于普通 GUI 程序的界面,包括工具栏、菜单栏、滚动条等。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
我在 中映射了一些实用的快捷键,用于处理剪贴板中的剪切/复制/粘贴操作gvim。这些快捷键分别用于剪切/复制/粘贴,是对内置x、y、的补充p,但适用于外部剪贴板(例如,OS 剪贴板)。我还添加了<leader>v(例如,,v)功能,用于在粘贴文本后立即选中粘贴到 vim 中。
除了自定义快捷键之外,我还映射了一些功能键(例如键盘上的 F1 - F12 键)来执行有用的操作。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters