<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>xxxbrian.blog</title>
    <description>Hi, I'm Bojin Li, a Student studying at the University of New South Wales. 🎓</description>
    <link>https://blog.bojin.co/</link>
    <atom:link href="https://blog.bojin.co/feed.xml" rel="self" type="application/rss+xml" />
    <pubDate>Sat, 12 Mar 2022 16:02:53 +0000</pubDate>
    <lastBuildDate>Sat, 12 Mar 2022 16:02:53 +0000</lastBuildDate>
    <generator>Jekyll v4.2.2</generator>
    
      <item>
        <title>在CentOS上安装并使用WARP代理出口ip (解锁Netflix IP限制）</title>
        <description>&lt;h2 id=&quot;warp&quot;&gt;WARP&lt;/h2&gt;

&lt;p&gt;Cloudflare WARP 是 Cloudflare 推出的一项网络隐私保护服务, 通过添加WARP出口可以绕过Netflix等流媒体对代理ip的封锁。(&lt;a href=&quot;https://blog.cloudflare.com/zh-cn/warp-for-desktop-zh-cn/&quot;&gt;Cloudefare官方中文介绍&lt;/a&gt;)&lt;/p&gt;

&lt;h2 id=&quot;wgcf&quot;&gt;WGCF&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/ViRb3/wgcf&quot;&gt;WGCF&lt;/a&gt;是WARP的非官方cli客户端。&lt;/p&gt;

&lt;p&gt;通过WGCF可以为VPS添加ipv4，ipv6代理,以达到解锁Netflix的目的。&lt;/p&gt;

&lt;h3 id=&quot;安装wgcf&quot;&gt;安装wgcf&lt;/h3&gt;

&lt;p&gt;执行以下命令：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;wgcf
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;wgcf
wget &lt;span class=&quot;nt&quot;&gt;-O&lt;/span&gt; wgcf https://github.com/ViRb3/wgcf/releases/download/v2.2.4/wgcf_2.2.4_linux_amd64
&lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x wgcf
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;初次使用需要注册用户并生成配置文件：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;./wgcf register
./wgcf generate
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;随后就可以在程序目录中找到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wgcf-account.toml&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wgcf-profile.conf&lt;/code&gt;两个新生成的文件。&lt;/p&gt;

&lt;h3 id=&quot;配置wgcf&quot;&gt;配置wgcf&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wgcf-account.toml&lt;/code&gt;是你的WARP账户信息，如果你有WARP+账户可以替换成你自己的账户; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wgcf-profile.conf&lt;/code&gt;是WireGuard的配置文件，下载到本地保存。&lt;/p&gt;

&lt;h4 id=&quot;修改wgcf-profileconf&quot;&gt;修改wgcf-profile.conf&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;WG连接后是内核层级的软件，会建立自己的虚拟网卡，且WARP客户端均为内网NAT地址，当双栈流量均被WG接管后我们就无法再从原有的IP连接到服务器了。因此在IPv4与IPv6之间必须做一个取舍，以防这样的情况发生。&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;可以自己把&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;engage.cloudflareclient.com&lt;/code&gt;解析成IP，对Endpoint修改成ipv4或者ipv6保存即可。&lt;/p&gt;

&lt;p&gt;修改配置文件就两种情况：&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;最后一行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Endpoint=engage.cloudflareclient.com：2048&lt;/code&gt;修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;162.159.192.1:2408&lt;/code&gt;,删除&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowedIPs = 0.0.0.0/0&lt;/code&gt;接管本地IPv4路由。&lt;/li&gt;
  &lt;li&gt;最后一行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Endpoint=engage.cloudflareclient.com：2048&lt;/code&gt;修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[2606:4700:d0::a29f:c001]:2408&lt;/code&gt;,删除&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllowedIPs = ::/0&lt;/code&gt;接管本地IPv6路由。&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;安装wireguard客户端&quot;&gt;安装Wireguard客户端&lt;/h3&gt;

&lt;p&gt;CentOS7：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;epel-release elrepo-release
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;yum-plugin-elrepo
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;kmod-wireguard wireguard-tools
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;其它系统的命令可以参考&lt;a href=&quot;https://www.wireguard.com/install/&quot;&gt;官方网站&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;安装完成后，&lt;strong&gt;重启VPS&lt;/strong&gt;。&lt;/p&gt;

&lt;h3 id=&quot;配置wireguard&quot;&gt;配置Wireguard&lt;/h3&gt;

&lt;p&gt;把刚刚修改好的配置文件wgcf-profile.conf上传至&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/wireguard&lt;/code&gt;,并重命名为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wgcf.conf&lt;/code&gt;。&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nb&quot;&gt;cp &lt;/span&gt;wgcf-profile.conf /etc/wireguard/wgcf.conf
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;启动wgcf&quot;&gt;启动wgcf&lt;/h3&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#加载内核模块&lt;/span&gt;
modprobe wireguard
&lt;span class=&quot;c&quot;&gt;#检查WG模块加载是否正常&lt;/span&gt;
lsmod | &lt;span class=&quot;nb&quot;&gt;grep &lt;/span&gt;wireguard
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;开关隧道的命令为：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c&quot;&gt;#开启隧道&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;wg-quick up wgcf
&lt;span class=&quot;c&quot;&gt;#关闭隧道&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;wg-quick down wgcf
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果VPS出口没有走ipv6的话，需要这编辑&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/gai.conf&lt;/code&gt; 文件（没有的话就新建），修改为以下内容：&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;label ::1/128 0
label ::/0 1
label fd01::/16 1
label 2002::/16 2
label ::/96 3
label ::ffff:0:0/96 4
label fec0::/10 5
label fc00::/7 6
label 2001:0::/32 7
precedence ::1/128 50
precedence ::/0 40
precedence fd01::/16 40
precedence 2002::/16 30
precedence ::/96 20
precedence ::ffff:0:0/96 10
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;检测是否可以观看Netflix：&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;wget &lt;span class=&quot;nt&quot;&gt;-O&lt;/span&gt; nf https://github.com/sjlleo/netflix-verify/releases/download/2.6/nf_2.6_linux_amd64 &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;chmod&lt;/span&gt; +x nf &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; clear &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; ./nf
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;检测结果：&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-06-21-install-warp-in-centos/netflix-verify.png&quot; alt=&quot;Netflix-verify&quot; /&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 21 Jun 2021 15:01:31 +0000</pubDate>
        <link>https://blog.bojin.co/2021/06/21/install-warp-in-centos/</link>
        <guid isPermaLink="true">https://blog.bojin.co/2021/06/21/install-warp-in-centos/</guid>
        
        <category>笔记</category>
        
        <category>CentOS</category>
        
        <category>Netflix</category>
        
        <category>梯子</category>
        
        
      </item>
    
      <item>
        <title>Vim 8文本处理实战</title>
        <description>&lt;p&gt;本文介绍了各种常用的文本编辑方法和程序设计中的实用操作，深入Vim内部的数据结构和VimScript脚本编程，内容详实。本文基于Vim 8平台，介绍了前沿分支Neovim，还推荐了更先进的Oni编辑器，兼容并包，集Vim社区典型使用经验和发展趋势于一体。&lt;/p&gt;

&lt;p&gt;本文面向的读者群体是所有使用Vim的程序员，书中的示例文本为Python代码，并详细介绍了Git和正则表达式。读者需要对操作系统和程序设计有基本的了解，特别是需要了解Linux操作系统的基本使用。虽然本文尝试兼顾三大操作系统，但毫无疑问书中内容以Linux为主。本文可以帮助读者完善Vim技能，增加程序设计的知识储备。&lt;/p&gt;

&lt;h2 id=&quot;关于作者&quot;&gt;关于作者&lt;/h2&gt;

&lt;p&gt;Ruslan Osipov 是 Google 公司的软件工程师，也是一名旅游爱好者和业余博主。他自学成才，2012 年开始发布个人的 Vim 笔记。从那时开始，Ruslan 就越来越关注这款强大的编辑器，以及那些可优化工作流程的应用。&lt;/p&gt;

&lt;h2 id=&quot;本文的读者&quot;&gt;本文的读者&lt;/h2&gt;

&lt;p&gt;本文适用于初级、中级和高级程序员。本文将介绍如何高效地将 Vim 应用于日常工作流程的方方面面。虽然书中涉及了 Python，但 Python 或 Vim 的经验并不是阅读本文所必需的&lt;/p&gt;

&lt;h2 id=&quot;本文的内容提要&quot;&gt;本文的内容提要&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;第 1 章，开始 Vim 之旅。介绍了 Vim 的基本概念。&lt;/li&gt;
  &lt;li&gt;第 2 章，高级编辑和文本浏览。介绍了光标移动方法和更复杂的编辑操作，另外，还介绍了几种插件。&lt;/li&gt;
  &lt;li&gt;第 3 章，使用先导键——插件管理。介绍了模式、键盘映射和插件管理。&lt;/li&gt;
  &lt;li&gt;第 4 章，理解文本。介绍如何基于语义地使用代码库，并在代码库中浏览文件。&lt;/li&gt;
  &lt;li&gt;第 5 章，构建、测试和执行。介绍如何在编辑器内外运行代码。&lt;/li&gt;
  &lt;li&gt;第 6 章，用正则表达式和宏来重构代码。深入介绍代码重构操作。&lt;/li&gt;
  &lt;li&gt;第 7 章，定制自己的 Vim。讨论了如何进一步定制个人的 Vim 工作流程。&lt;/li&gt;
  &lt;li&gt;第 8 章，卓尔不凡的 Vimscript。深入介绍了 Vim 提供的强大脚本语言。&lt;/li&gt;
  &lt;li&gt;第 9 章，Neovim。推介了一种新的 Vim 变体。&lt;/li&gt;
  &lt;li&gt;第 10 章，延伸阅读。本章为读者提供了一些建议以供参考，并推荐了一些读者可能会感兴趣的资源站点。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;配套资源&quot;&gt;配套资源&lt;/h2&gt;

&lt;p&gt;本文源代码: &lt;a href=&quot;https://github.com/xxxbrian/xxxbrian.blog/blob/master/img/in-post/2021-05-12-vim/book-res/B11044_Code.zip?raw=true&quot;&gt;B11044_Code.zip&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;第-1-章开始-vim-之旅&quot;&gt;第 1 章　开始 Vim 之旅&lt;/h1&gt;

&lt;p&gt;本文将向读者介绍如何更好地使用 Vim 和 Vim 插件，以及一些与 Vim 理念一脉相承的工具。&lt;/p&gt;

&lt;p&gt;每个工具背后都有它的独特理念，Vim 也不例外。Vim 引入了一种不同的文本处理方式，这种方式是现如今大部分人并不熟悉的。&lt;/p&gt;

&lt;p&gt;本章的内容是为使用 Vim 作铺垫，重点介绍这种理念的与众不同之处，并向读者推荐一些良好的编辑习惯，帮助读者体验一个操作更友好的 Vim，并确保读者能够在工作中找到适合自己的工具。为了让示例更加具体，本章会使用 Vim 来创建一个短小的 Python 程序。&lt;/p&gt;

&lt;p&gt;本章会涉及如下主题。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;模式界面和无模式界面的对比，为什么 Vim 与众不同。&lt;/li&gt;
  &lt;li&gt;Vim 的安装和基本编辑功能。&lt;/li&gt;
  &lt;li&gt;Vim 的图形用户界面 gVim。&lt;/li&gt;
  &lt;li&gt;通过配置 Vim 来编写 Python，修改配置文件&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;。&lt;/li&gt;
  &lt;li&gt;常用文件操作，包括打开、修改、保存和关闭文件。&lt;/li&gt;
  &lt;li&gt;光标移动操作，包括通过箭头键移动、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hjkl&lt;/code&gt;键、逐个单词移动、逐段落移动等。&lt;/li&gt;
  &lt;li&gt;文件的简单编辑，将编辑命令与光标移动命令结合起来。&lt;/li&gt;
  &lt;li&gt;持久化的撤销历史。&lt;/li&gt;
  &lt;li&gt;浏览 Vim 的内置手册。&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;11-技术性要求&quot;&gt;1.1 　技术性要求&lt;/h2&gt;

&lt;p&gt;本章示例是一些基本的 Python 程序，读者没必要专门去下载与本章相关的任何代码，因为这些代码都可以从头开始编写。如果读者没有跟上节奏而需要更多指引，可以在异步社区中找到示例代码。&lt;/p&gt;

&lt;p&gt;本文用 Vim 编写 Python 代码，并且假定读者对该语言比较熟悉，版本为 Python 3。&lt;/p&gt;

&lt;p&gt;如果读者习惯 Python 2 的语法，则只需要修改&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print()&lt;/code&gt;命令，就可以将 Python 3 示例转换为 Python 2 了。比如，将所有的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print('Woof!')&lt;/code&gt;换成&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print 'Woof!'&lt;/code&gt;，代码就可以作为 Python 2 版本正常运行了。&lt;/p&gt;

&lt;p&gt;本章还会介绍如何创建和修改 Vim 配置文件，即&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件。最终的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件可以在异步社区中找到。&lt;/p&gt;

&lt;h2 id=&quot;12-开始对话关于模式界面&quot;&gt;1.2 　开始对话（关于模式界面）&lt;/h2&gt;

&lt;p&gt;如果读者曾经编辑过文本，很可能已经非常熟悉无模式（modeless）界面了，因为这是现代主流文本编辑器的默认选项，大多数人也是通过它来学习文本处理的。“无模式”指的是每个界面元素都只有一个功能，每个按钮都对应于屏幕上的一个字母或某种其他操作，每个按键（或组合键）总是做同样的事：此应用程序总是以单一模式来执行操作。&lt;/p&gt;

&lt;p&gt;但这并不是文本处理的唯一方式。那么现在，欢迎来到模式界面的世界。在这里，根据上下文的不同，每个行为可能对应于不同的操作。现在常见的模式界面应用设备为智能手机，每当打开一个不同的应用或菜单时，在屏幕上单击一下就会执行不同的功能。&lt;/p&gt;

&lt;p&gt;对于文本编辑器，情况类似。Vim 就是一款模式编辑器，即在不同的上下文，单击一个按钮会产生不同的行为结果。当 Vim 处于插入模式（用于文本输入的模式）时，单击 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; 键会在屏幕上得到 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; 。但当切换到不同的模式时，按 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;o&lt;/code&gt; 键的行为会发生变化，比如在光标下面添加新行。&lt;/p&gt;

&lt;p&gt;使用 Vim 就像是与编辑器进行对话。通过命令 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d3w\[&lt;/code&gt; 刚好是删除（delete）3 个单词（word）的英文缩写， &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;]&lt;/code&gt; 可以删除后面 3 个词；通过命令 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ci&quot;[&lt;/code&gt; 改变（change）引号里面（inside）的英文缩写]则可以改变引号里面的文本。&lt;/p&gt;

&lt;p&gt;编辑速度快并不是 Vim 的卖点。Vim 让用户置身于文本处理的流程中，不需要因为找鼠标而打乱节奏；也不需要按 17 次方向键到达页面中的某个位置；更不需要在复制粘贴时通过鼠标操作来小心翼翼地选择文本。&lt;/p&gt;

&lt;p&gt;当使用无模式编辑器时，工作流程总是会被打断。而对于模式编辑器，特别是 Vim，文本处理就像是与编辑器进行了一次亲密交谈，而且是用一种一致的语言与编辑器进行交流，比如删除 3 个单词（命令为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d3w&lt;/code&gt; ）、改变引号内文本（命令为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ci&quot;&lt;/code&gt; ）。通过 Vim，文本编辑变成一种更从容的操作。&lt;/p&gt;

&lt;h2 id=&quot;13-安装&quot;&gt;1.3 　安装&lt;/h2&gt;

&lt;p&gt;Vim 可在各种操作系统中安装，而且在 Linux 和 macOS 中是自带的（不过，读者可能需要将其升级到更新的版本）。在接下来的章节中，请读者确认自己的操作系统，并根据指令设置好 Vim。&lt;/p&gt;

&lt;h3 id=&quot;131-在-linux-系统中设置-vim&quot;&gt;1.3.1 　在 Linux 系统中设置 Vim&lt;/h3&gt;

&lt;p&gt;Linux 操作系统自带 Vim，但是其版本可能比较旧了，而本文使用的 Vim 8 引入了一些急需的优化。首先，读者需要进入命令行界面，然后执行如下命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ git clone https://github.com/vim/vim.git
$ cd vim/src
$ make
$ sudo make install
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;如果读者在安装 Vim 时遇到问题，原因可能是系统中缺少一些依赖库。如果读者使用的是基于 Debian 的 Linux 发行版，下列命令可以用于安装常用的缺失依赖库。&lt;/p&gt;
&lt;blockquote&gt;

  &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ sudo apt-get install make build-essential libncurses5-dev

  libncursesw5-dev --fix-missing
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;  &lt;/div&gt;
&lt;/blockquote&gt;

&lt;p&gt;注意，这里的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&lt;/code&gt; 仅仅用来标识这是一个 Shell 命令，并不属于命令行的一部分。按照上述方法，可以成功将 Vim 更新到最新版本。当然，如果读者不在乎是否最新，仍然可以使用系统的包管理器来更新 Vim。不同的 Linux 发行版本使用不同的包管理器，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;发　行　版&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;安装最新 Vim 的命令&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;基于 Debian（Debian、Ubuntu、Mint）&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo apt-get update&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo apt-get install vim-gtk&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;CentOS（以及 Fedora 22 之前的版本）&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo yum check-update&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo yum install vim-enhanced&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Fedora 22+&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo dnf check-update&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo dnf install vim-enhanced&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Arch&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo pacman -Syu&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo pacman -S gvim&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;FreeBSD&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo pkg update&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt; &lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sudo pkg install vim&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;在上表中可以发现，Vim 在不同的软件库中使用不同的名称。基于 Debian 的发行版中的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim-gtk&lt;/code&gt; ，或 CentOS 上的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim-enhanced&lt;/code&gt; 提供了更多的功能（如图形用户界面支持）。&lt;/p&gt;

&lt;p&gt;有一点需要注意的是，包管理器软件仓库中的 Vim 版本一般会有所滞后，少则几个月，多则几年。&lt;/p&gt;

&lt;p&gt;现在已经准备好进入 Vim 世界了！可以通过如下命令打开一个 Vim 编辑器。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ vim
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;在现代的操作系统上，读者可以通过命令 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vi&lt;/code&gt; 打开 Vim，但这不是绝对的。在旧版本的系统上，两者是不同的程序。Vim 是 Vi 的继承者（Vim 是 Vi improved 的缩写），只不过，现如今 Vi 仅仅是指向 Vim 的一个别名。而且，我们没有理由使用 Vi 而不使用 Vim，除非由于某种原因无法安装 Vim。&lt;/p&gt;

&lt;h3 id=&quot;132-在-macos-系统中设置-vim&quot;&gt;1.3.2 　在 macOS 系统中设置 Vim&lt;/h3&gt;

&lt;p&gt;macOS 系统中已经安装好了 Vim，但是版本较旧。安装更新版本的 Vim 有很多种方法，这里介绍两种。第一种方法是使用 Homebrew 安装，这是 macOS 上的一种包管理器。不过，读者需要首先安装 Homebrew。第二种方法是下载 MacVim 的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dmg&lt;/code&gt;安装包，对于习惯了图形界面的 Mac 用户而言，这种安装体验会更熟悉一些。&lt;/p&gt;

&lt;p&gt;因为本文使用命令行进行交互，所以推荐使用 Homebrew 安装 Vim。但是如果读者对命令行实在不感兴趣，则可以使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dmg&lt;/code&gt;安装包完成 Vim 的安装。&lt;/p&gt;

&lt;h4 id=&quot;1使用-homebrew&quot;&gt;1．使用 Homebrew&lt;/h4&gt;

&lt;p&gt;Homebrew 是 macOS 上的一种第三方包管理器，它可以使用户方便地安装或更新到最新的软件。关于如何安装 Homebrew，读者可以在 Homebrew 官网中找到相关指令。编写本文的时候，Homebrew 的安装命令已经简化为一条命令行。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ /usr/bin/ruby -e &quot;$(curl –fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)&quot;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下图为该命令执行 Homebrew 安装过程所需要经历的一系列操作。执行操作后按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/7dd733598ebbc8a1.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果读者没有安装 Xcode（Xcode 通常是在 macOS 上进行与开发相关的行为的必备条件），则会得到一个 Xcode 的安装提示框。这里不会直接使用 Xcode，因而按照默认设置安装好就可以了。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这个过程可能会有点长，但如果一切顺利，最终会安装好 Homebrew。Homebrew 是一个神奇的工具，它的功能不仅仅是安装 Vim！安装完成时，会看到粗体字显示的&lt;strong&gt;安装成功!&lt;/strong&gt;提示。&lt;/p&gt;

&lt;p&gt;用下面的命令安装新版本的 Vim。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ brew install vim
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Homebrew 会安装好所有必要的依赖项，正常情况下，读者会看到如下图所示的结果。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/bd34219b814f0d5d.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;如果读者已经安装了 Homebrew，而且曾经安装过 Vim，则前面的命令将会产生一个错误。如果读者只是想更新到最新版本的 Vim，这时应该执行下列命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ brew upgrade vim
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;现在，已经准备好使用 Vim 了，那么用下面的命令开启 Vim 之旅吧。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ vim
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下图所示为 Vim 的启动界面。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/ad2eae5bc663b1b5.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h4 id=&quot;2下载dmg-安装包&quot;&gt;2．下载.dmg 安装包&lt;/h4&gt;

&lt;p&gt;首先，下载&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacVim.dmg&lt;/code&gt;。然后双击打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacVim.dmg&lt;/code&gt;，再将 Vim 图标拖曳到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Applications&lt;/code&gt;目录中，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/b936a4d7a9d87565.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;由于 Mac 的安全设置，因此当读者进入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Applications&lt;/code&gt;目录并尝试打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacVim&lt;/code&gt;应用时，系统可能会弹出下图中的错误提示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/0be2ea0b0403da13.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;为解决这个问题，可以打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Applications&lt;/code&gt;目录，找到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacVim&lt;/code&gt;，右键单击图标，选择&lt;strong&gt;Open&lt;/strong&gt;选项，系统会弹出如下图所示的对话框。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/a2555827212103a9.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;单击&lt;strong&gt;Open&lt;/strong&gt;按钮，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MacVim&lt;/code&gt;会正常启动，而且以后都不会再弹出这样的对话框。下图所示为 Vim 的启动界面。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/029209ef17587a74.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;133-在-windows-系统中设置-vim&quot;&gt;1.3.3 　在 Windows 系统中设置 Vim&lt;/h3&gt;

&lt;p&gt;在 Windows 操作系统下有两种安装 Vim 的方式：第一种是在 Cygwin 中安装命令行版本的 Vim，并在命令行中使用 Vim；第二种是安装 Vim 的图形界面版本 gVim（它也有在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cmd.exe&lt;/code&gt;上运行的终端版本）。建议读者尝试两种安装方式并从中选择喜欢的一种：gVim 更像 Windows 系统中的其他应用程序（也更容易安装），而 Cygwin 可能对于习惯了 UNIX Shell 命令行的人来说更亲切一些。&lt;/p&gt;

&lt;h4 id=&quot;在-cygwin-中感受类-unix-操作体验&quot;&gt;在 Cygwin 中感受类 UNIX 操作体验&lt;/h4&gt;

&lt;p&gt;Cygwin 是 Windows 的类 UNIX 环境，它提供了一种命令行界面，致力于将强大的 UNIX Shell 命令行以及相关的支撑工具带到 Windows 操作系统中。&lt;/p&gt;

&lt;p&gt;（1）安装 Cygwin&lt;/p&gt;

&lt;p&gt;在开始安装之前，需要先浏览 Cygwin 官网 ，然后下载&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup-x86_64.exe&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;setup-x86.exe&lt;/code&gt;，它们分别对应于 64 位和 32 位的版本。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果不确定操作系统是 32 位还是 64 位，可以打开“&lt;strong&gt;控制面板-&amp;gt;系统和安全-&amp;gt;系统&lt;/strong&gt;”，找到“&lt;strong&gt;系统类型&lt;/strong&gt;”。比如，很多 64 位的 Windows 机器上会显示&lt;strong&gt;系统类型：64 位操作系统，基于 x64 的处理器&lt;/strong&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;双击下载的可执行文件，会弹出如下图所示的 Cygwin 安装窗口。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/97284d6055052e5a.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;在接下来的安装工程中，单击&lt;strong&gt;Next&lt;/strong&gt;按钮数次，即以此选择如下默认设置。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;下载源（Download source）：从互联网地址下载，而不是本地缓存。&lt;/li&gt;
  &lt;li&gt;根目录（Root directory）：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\cygwin 64&lt;/code&gt;（或其他推荐的默认设置）。&lt;/li&gt;
  &lt;li&gt;为哪些用户安装（Install for）：所有用户。&lt;/li&gt;
  &lt;li&gt;本地软件包目录（Local package directory）：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Downloads&lt;/code&gt;（或其他推荐默认设置）。&lt;/li&gt;
  &lt;li&gt;网络连接（Internet connection）：使用系统代理设置。&lt;/li&gt;
  &lt;li&gt;下载站点（Download site）：&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http://cygwin.mirror.constant.com&lt;/code&gt; （或任意其他可用选项）。&lt;/li&gt;
&lt;/ul&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;在完成这些步骤之后，会看到选择软件包的界面。这里，本文将选择&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gvim&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim-doc&lt;/code&gt;软件包。较容易的方法是在搜索框中输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim&lt;/code&gt;，展开**All&lt;/td&gt;
      &lt;td&gt;Editors**类别，然后单击相应的软件包旁边的图标，如下图所示。&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/efbac38fe6f9f292.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;上图显示 Vim 版本为 8.0.1567-1。编写本文时，也就是 2018 年 11 月，这是 Cygwin 中唯一可用的版本。与 8.1 版本相比，8.0 版本主要缺少了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:terminal&lt;/code&gt;命令（见第 5 章）。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;读者可能还需要安装 Net 类别中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;curl&lt;/code&gt;，以及 Devel 类别中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;git&lt;/code&gt;，因为在第 3 章中会用到这两个工具。另外，安装 Utils 类别中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dos2unix&lt;/code&gt;也大有好处，此工具可将文本中 Windows 样式的换行符转换成 Linux 样式的换行符（使用 Vim 通常会遇到这个问题）。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;然后，单击两次&lt;strong&gt;Next&lt;/strong&gt;按钮，正式开始这些软件包的安装过程。安装过程会持续一段时间。&lt;/p&gt;

&lt;p&gt;有时候，安装过程中会产生一些 post-install 脚本错误，大部分情况下可以安全地忽略（除非其中包含 Vim 相关的错误—— 这时可能就需要参考 Google 的意见：搜索错误消息中的文本，然后尝试找到解决方案）。&lt;/p&gt;

&lt;p&gt;再接着单击&lt;strong&gt;Next&lt;/strong&gt;按钮数次，即默认选择如下选项。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;在桌面上创建图标。&lt;/li&gt;
  &lt;li&gt;在开始菜单中添加图标。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;现在已经成功安装了 Cygwin 和 Cygwin 中的 Vim。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果读者还需要在 Cygwin 中安装其他软件包，则只需要再次打开安装包可执行文件，然后选择需要的软件包。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;（2）使用 Cygwin&lt;/p&gt;

&lt;p&gt;Cygwin 的应用程序可能叫作&lt;strong&gt;Cygwin64 Terminal&lt;/strong&gt;或&lt;strong&gt;Cygwin Termianl&lt;/strong&gt;，这取决于操作系统的类型。找到其图标，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/0d0c563d7ceaf288.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;打开它，可以看到如下图所示的命令行提示界面，Linux 用户应该相当熟悉了。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/bff44f6d4a37a6ba.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cygwin 支持本文中用到的所有 UNIX 样式的 Shell 命令行。如果部分命令行需要修改才能用于 Cygwin，本文也会特别说明。但是目前，只需要简单地打开 Vim 使用即可，直到第 2 章都不会有任何问题。在命令行提示符中输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim&lt;/code&gt;，按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键启动 Vim，界面如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/9eba7afcecc07589.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cygwin 是在 Windows 环境下体验 Linux 系统 Shell 命令的一种方式，这意味着，一旦在阅读本文时选择使用 Cygwin，就需要遵循 Linux 系统中的指令和约定。同时，还需要注意 Windows 样式的换行符和 Linux 样式的换行符，因为 Windows 和 Linux 处理换行的方式不同。如果在 Vim 中遇到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;^M&lt;/code&gt;字符无法识别，则对相应的文件执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dos2unix&lt;/code&gt;命令就可以解决。&lt;/p&gt;

&lt;h3 id=&quot;134-可视化的-vimgvim&quot;&gt;1.3.4 　可视化的 Vim：gVim&lt;/h3&gt;

&lt;p&gt;通过对比命令行 Vim 和 gVim，本节将详细介绍 Vim 的图形化版本 gVim。&lt;/p&gt;

&lt;p&gt;与 Windows 系统中其他程序的安装过程相比，gVim 的安装过程要更图形化一些。在浏览器中打开&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Vim&lt;/code&gt;网站，下载一个可执行的安装包。编写本文时（2018 年 11 月），这个二进制文件名为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gvim81.exe&lt;/code&gt;，其中的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;81&lt;/code&gt;代表版本 8.1。打开这个可执行文件，会弹出如下图所示的提示框。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/46bf6c4bcc51611d.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;单击&lt;strong&gt;Yes&lt;/strong&gt;按钮，然后单击&lt;strong&gt;I Agree&lt;/strong&gt;按钮，直到出现&lt;strong&gt;Installation Options&lt;/strong&gt;界面。大部分默认设置是满足本文需求的，如果需要在命令行中使用 Vim，可以通过启用&lt;strong&gt;Create .bat files for command line use&lt;/strong&gt;选项来实现。这个选项让读者可以在 Windows 命令提示符中使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;vim&lt;/code&gt;。本文中的一些例子需要用到命令提示符，因此启用这个选项对于接下来的阅读是有帮助的。&lt;/p&gt;

&lt;p&gt;下图所示为&lt;strong&gt;Installation Options&lt;/strong&gt;界面的截屏，注意，图中已经启用了所有选项。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/467fff34d0b9e169.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;单击&lt;strong&gt;Next&lt;/strong&gt;按钮，设置如下选项。&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;选择安装类型（Select the type of install）&lt;/strong&gt;：典型（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Typical&lt;/code&gt;），（启用&lt;strong&gt;Create .bat files for command line use&lt;/strong&gt;选项之后，安装类型会自动变成&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Custom&lt;/code&gt;）。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;不针对 Windows 行为重新映射按键（Do not remap keys for Windows behavior）&lt;/strong&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;右键打开菜单，左键开始可视模式（Right button has a popup menu, left button starts visual mode）&lt;/strong&gt;。&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;安装路径（Destination Folder）&lt;/strong&gt;： &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Program Files (x86)\Vim&lt;/code&gt;（或其他推荐的默认值）。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;完成这些选项的设置之后，单击&lt;strong&gt;Install&lt;/strong&gt;按钮，然后单击&lt;strong&gt;Close&lt;/strong&gt;按钮，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/86aa07608337feb0.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;安装结束时系统会询问是否查看 README 文件，单击&lt;strong&gt;No&lt;/strong&gt;按钮即可(谁会现在就看手册呢？)，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/18067d8c1afa6ffc.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;安装完成后，桌面上会出现一些新的图标，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/6f58994a2032992c.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;双击此图标，Vim 就打开了！&lt;/p&gt;

&lt;h3 id=&quot;135-安装结果的验证和故障排除&quot;&gt;1.3.5 　安装结果的验证和故障排除&lt;/h3&gt;

&lt;p&gt;不管在哪个平台上安装 Vim，最好先确认一下 Vim 的相关功能是否都已经启用。在命令行中，执行如下命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ vim --version
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;可以看到如下图所示的输出结果，它列出了一系列功能，每项功能前面都有加号（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;）或减号（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt;）。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/16061205d68c0e79.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;这里，加号（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;）表示功能启用，减号（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt;）表示功能未启用。上图中的 Vim 支持 Python 2（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+python&lt;/code&gt;），而不支持 Python 3（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-python3&lt;/code&gt;）。要想解决这个问题，可以重新编译 Vim 并启用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+python3&lt;/code&gt;，或者寻找一个支持 Python 3 的 Vim 发布版本。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 可以支持的所有功能列表参见&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help feature-list&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;在 Linux 系统中重新编译一个支持 Python 3 的 Vim 8.1，可以执行如下命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ git clone https://github.com/vim/vim.git
$ cd vim/src
$ ./configure --with-features=huge --enable-python3interp
$ make
$ sudo make install
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;传入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--with-features=huge&lt;/code&gt;编译选项，是为了启用 Vim 的大部分功能。不过，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--with-features=huge&lt;/code&gt;并不涉及语言的绑定，因此需要显式地启用 Python 3。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;一般而言，如果读者感觉自己的 Vim 不像其他 Vim 那样运行（包括本文中描述的行为），那么有可能是因为缺失了某个 Vim 功能。这和读者的计算机操作系统以及特定的功能有关，因而安装过程可能或多或少会有不同。通过在网上搜索 Install Vim &amp;lt;version&amp;gt; with + &amp;lt;feature&amp;gt; on &amp;lt;operating system&amp;gt;可能会有所帮助。&lt;/p&gt;

&lt;h2 id=&quot;14-命令行-vim-和-gvim&quot;&gt;1.4 　命令行 Vim 和 gVim&lt;/h2&gt;

&lt;p&gt;通过前面介绍的指令，读者应该已经安装了两种 Vim——命令行 Vim 和 gVim。Windows 系统下的 gVim 如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim//0f44832bea190b4e.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;gVim 实际上是为 Vim 绑定了一个图形用户界面（GUI），它具有更好的鼠标支持，还有更多上下文菜单。与终端模拟器相比，它还支持更多的配色，并具备一些现代图形用户界面应有的优质功能。在 Windows 系统中，读者可以通过打开桌面图标&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gVim 8.1&lt;/code&gt;来启动 gVim，而在 Linux 和 macOS 系统中，可通过如下命令行启动。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ gvim
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Windows 用户可能会更青睐于 gVim。不过，由于本文更关注于文本编辑技巧中的效率方面，因此会避免涉及 gVim 菜单，虽然它们也很直观，但会影响用户专注于自己的工作流程。本文会更关注 Vim 的非图形界面版本，但这些内容同样适用于 gVim。这两个版本的 Vim 共享配置文件，相互之间切换使用完全没有问题。&lt;/p&gt;

&lt;p&gt;总体来说，gVim 对新手更友好一些。&lt;/p&gt;

&lt;h2 id=&quot;15-通过vimrc文件来配置-vim&quot;&gt;1.5 　通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件来配置 Vim&lt;/h2&gt;

&lt;p&gt;Vim 从一个名为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;的文件中读取配置信息。Vim 安装好后就可以使用，但是有些选项会使程序编码更容易。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;在类 UNIX 系统中，以句点.开头的文件为隐藏文件。为了看到这些文件，可以运行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ls -a&lt;/code&gt;命令行。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;在 Linux 和 macOS 系统中，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;位于用户根目录中（完整路径为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/home/&amp;lt;用户名&amp;gt;/.vimrc&lt;/code&gt;）。读者也可以打开一个命令行终端，并通过如下命令进入终端。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ echo $HOME
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Windows 系统不允许文件名中出现句点，因此配置文件的名称为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_vimrc&lt;/code&gt;，其路径通常为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Users\&amp;lt;用户名&amp;gt;_vimrc&lt;/code&gt;。读者也可以通过命令提示符中的如下命令找到其所在的目录。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ echo %USERPROFILE%
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果遇到了问题，可以打开 Vim，输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:echo $MYVIMRC&lt;/code&gt;，然后按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键。Vim 会显示它正在使用的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;的路径。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;找到操作系统存储 Vim 配置文件的目录，然后将准备好的配置文件放入其中。读者也可以从本文的官方 GitHub 仓库中找到本章涉及的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;。下列代码为本章中使用的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件的内容。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;syntax on                 &quot; 支持语法高亮显示
filetype plugin indent on &quot; 启用根据文件类型自动缩进

set autoindent            &quot; 开始新行时处理缩进
set expandtab             &quot; 将制表符Tab展开为空格，这对于Python尤其有用
set tabstop=4             &quot; 要计算的空格数
set shiftwidth=4          &quot; 用于自动缩进的空格数

set backspace=2           &quot; 在多数终端上修正退格键Backspace的行为

colorscheme murphy        &quot; 修改配色
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;上面的代码中，双引号开头的内容为注释，会被 Vim 忽略。这些设置还是比较合理的，比如语法高亮和一致的缩进。它同时还解决了不同环境中退格键可能出现不同行为的问题。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;当编写 Vim 配置文件时，可以先尝试相应的设置，然后再写到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件中去。操作过程为先输入冒号，然后输入相应的命令，再按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键即可。比如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:set autoindent&lt;/code&gt;（按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键执行）。如果想知道某种设置当前的值，可以在命令后面加上问号，比如执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:set tabstop?&lt;/code&gt;命令会显示出当前的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tabstop&lt;/code&gt;的值。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;此例中还修改了配色，让屏幕显示效果更好一些，但这并不是必需的。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 8 自带如下主题配色。&lt;/p&gt;

  &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;blue、darkblue、default、delek、desert、elflord、evening、industry、koehler、morning、murhpy、pablo、peachpuff、ron、shine、slate、torte、zellner。&lt;/code&gt;读者可以尝试其中一种配色主题，方法是输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:colorscheme&amp;lt;name&amp;gt;&lt;/code&gt;，然后按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键；也可以在所有可用的配色主题之间循环切换，方法是输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:colorscheme&lt;/code&gt;，然后输入一个空格，并多次按 Tab 键。第 7 章中有更多关于 Vim 的配置和配色的介绍，届时读者可以拥有完全属于自己的 Vim。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;16-常用操作特别是如何退出-vim&quot;&gt;1.6 　常用操作（特别是如何退出 Vim）&lt;/h2&gt;

&lt;p&gt;下图所示为一位 Vim 用户在 Twitter 上发布的帖子：我已经使用 Vim 两年了，主要原因是我不知道怎么退出来。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/9e9cb23ac8ab16ef.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;现在，本文将介绍如何在不使用鼠标或菜单的情况下与 Vim 进行交互。编程本身是一种要求精力高度集中的任务，没有人会愿意一直单击菜单，让双手一直保持在键盘中心位置也有助于避免在鼠标和键盘之间频繁切换。&lt;/p&gt;

&lt;h3 id=&quot;161-打开文件&quot;&gt;1.6.1 　打开文件&lt;/h3&gt;

&lt;p&gt;首先，请读者打开自己最喜欢的命令行终端（Linux 和 macOS 系统中是终端，Windows 系统中为 Cygwin），跟随下面的步骤来编写一个非常基础的 Python 程序。&lt;/p&gt;

&lt;p&gt;先从一个简单的开平方根计算器开始，运行如下命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ vim animal_farm.py
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果读者使用 gVim，那么可以在&lt;strong&gt;File&lt;/strong&gt;菜单中单击&lt;strong&gt;Open&lt;/strong&gt;选项，然后打开一个文件。有时候，读者可能确实需要一个图形界面。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;这会打开一个名为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animal_farm.py&lt;/code&gt;的文件。如果此文件存在，则读者会看到它的内容；如果文件不存在，则得到一个空白界面，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/9f45dcbe38941706.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;在上图中，Vim 的底部状态中显示了文件名，旁边还有&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[New File]&lt;/code&gt;字样，表示这是一个新文件。现在读者已经用 Vim 打开了第一个文件。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 的状态栏通常会包含很多有用的信息，它是 Vim 与用户交流的主要途径，因此需要保持对状态栏中的消息的关注。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;如果之前已经打开过 Vim，则可以用如下命令加载一个文件（别忘了命令后面要按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键）。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;:e animal_farm.py
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这有可能是读者在 Vim 中运行的第一条命令。输入冒号字符&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:&lt;/code&gt;表示进入命令行模式，在此模式下输入的文字会被 Vim 解析为命令。按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键可以结束命令，通过 Vim 命令可以执行很多复杂的操作，包括访问系统的命令行。命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:e&lt;/code&gt;表示编辑（edit）。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 的帮助文档中通常将&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键记为回车（carriage return）的意思。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;162-修改文字&quot;&gt;1.6.2 　修改文字&lt;/h3&gt;

&lt;p&gt;默认情况下，Vim 处于正常模式（normal mode），即每个键都对应于某个命令。输入命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt;将使 Vim 进入插入模式（insert mode）。它会在底部的状态栏中显示– INSERT –字样（如果读者使用的是 gVim，则光标由块状变为竖线状），如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/122a0d305d8ab530.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;插入模式下的行为和在其他无模式编辑器中相似。正常情况下，除添加新文本之外，本文不会花太多篇幅介绍插入模式。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;本文中已经涉及了 3 种 Vim 模式：命令行模式、正常模式和插入模式。本文还会介绍很多模式，详情参见第 3 章。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;现在输入如下图所示的代码，这就是之前提到的 Python 程序。本章将反复使用这几行代码。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/1d8c898039731c06.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;按下 Esc 键可以返回到 Vim 的正常模式。这时，状态栏上的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-- INSERT --&lt;/code&gt;字样消失，可以继续在 Vim 中输入命令。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;上述代码并不是 Python 编程的最佳实践，这里只是用它来展示 Vim 的一些功能。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;163-保存和关闭文件&quot;&gt;1.6.3 　保存和关闭文件&lt;/h3&gt;

&lt;p&gt;保存文件可执行&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w&lt;/code&gt;命令。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;注意，在输入命令后按下&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w&lt;/code&gt;表示写（write）的意思。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w&lt;/code&gt;命令后面也可以接一个文件名，并另存为新文件。修改后的内容会保存到这个新文件中，当前文件也变成了这个新文件。尝试执行命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w animal_farm2.py&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;退出 Vim，并检查一下文件是否已经生成。命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:q&lt;/code&gt;表示退出（quit）的意思。也可以将写和退出这两个命令组合为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:wq&lt;/code&gt;，表示先保存后退出。&lt;/p&gt;

&lt;p&gt;如果修改了文件，但是不想保存而直接退出 Vim，可以用命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:q!&lt;/code&gt;强制退出 Vim。命令后面的感叹号表示强制执行。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 的许多命令都有长短两个版本。比如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:e&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:q&lt;/code&gt;分别是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:edit&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:write&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:quit&lt;/code&gt;的短版本。在 Vim 手册中，命令的可选部分通常置于一对中括号中，比如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:w[rite]&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:e[dit]&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;退出 Vim 之后又回到了系统的命令行，可以检查一下当前目录中的内容是否发生了变化，如下列命令所示。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$ ls
$ python3 animal_farm.py
$ python3 animal_farm.py cat dog sheep
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;在 UNIX 中，ls 表示列出当前目录的内容。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 animal_farm.py&lt;/code&gt;表示用 Python 3 解释器来执行这个脚本。&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;python3 animal_farm.py cat dog sheep&lt;/code&gt;表示执行此脚本，并传入（&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat, dog, sheep&lt;/code&gt;）这 3 个参数。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;下图中显示了这 3 条命令的输出结果。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/219b67adbf8fd261.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;164-关于交换文件&quot;&gt;1.6.4 　关于交换文件&lt;/h3&gt;

&lt;p&gt;默认情况下，Vim 用交换文件跟踪文件的变化情况。当用户编辑文件的时候，Vim 会自动产生交换文件。交换文件的作用是恢复文件内容，以防止用户的 Vim、SSH 会话或系统崩溃。一旦出现上述问题，或者由于其他失误意外地退出 Vim，再次用 Vim 打开同一个文件时，就会看到如下图所示的画面。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/3e0ee5c0892b15f2.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;这时，可以输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;从交换文件中恢复文件，或者输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt;直接忽略交换文件。如果读者决定从交换文件中恢复，为了避免下次打开此文件时再次出现这个提示，可以输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt;删除交换文件。&lt;/p&gt;

&lt;p&gt;默认情况下，Vim 会在原始文件所在的目录下生成类似于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;filename&amp;gt;.swp&lt;/code&gt;或&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.&amp;lt;filename&amp;gt;.swp&lt;/code&gt;的文件。为避免这些交换文件污染文件系统，可以修改这个默认行为，使 Vim 将所有交换文件都统一存放在同一个目录中。要实现这个设置，可以在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件中加入如下内容。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;set directory=$HOME/.vim/swap//
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果使用 Windows 系统，设置命令为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set directory= %USERDATA%.vim\swap//&lt;/code&gt;（注意最后两个斜线的方向）。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;或者，也可以选择完全禁止交换文件，在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;中加入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;set noswapfile&lt;/code&gt;即可。&lt;/p&gt;

&lt;h3 id=&quot;165-随意移动与编辑器对话&quot;&gt;1.6.5 　随意移动：与编辑器对话&lt;/h3&gt;

&lt;p&gt;Vim 中的光标移动方式比大部分传统编辑器都要更便捷高效一些。本节只介绍基本的操作。&lt;/p&gt;

&lt;p&gt;在 Vim 中可以用方向键或字母&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;j&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;k&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;l&lt;/code&gt;来逐个字符地移动光标，这是效率最低，但也是最精确的移动方式，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;按键&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;替代键&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;行为&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向左箭头键&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向左移动光标&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;j&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向下箭头键&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向下移动光标&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;k&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向上箭头键&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向上移动光标&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;l&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向右箭头键&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向右移动光标&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;这几个字母不是随意选的，从下图中可以发现它们在方位上的对应关系。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/d605aa5c2e1eae1d.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Vi（Vim 的前身）是从 ADM-3A 终端机上创造出来的，如下图所示，这台机器并没有方向键，因而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;h&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;j&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;k&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;l&lt;/code&gt;被选择用来表示方向。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/6caff570fe5b2c4b.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;习惯用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hjkl&lt;/code&gt;来移动光标有很多好处：双手就可以集中于键盘中央，从而使用户更专注于工作流程。此外，许多应用也将&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hjkl&lt;/code&gt;用作方向键，也许数目多到让人惊讶。&lt;/p&gt;

&lt;p&gt;现在，读者可能已经倾向于多次敲击这些方向键到达目标位置了，但是还有更好的方式。在每一个命令之前可以加一个数字，表示重复这条命令的次数。比如，敲击&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5j&lt;/code&gt;会让光标下移 5 次，而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;14l&lt;/code&gt;会让光标右移 14 个字符。这条规则适用于本文提到的大多数命令。&lt;/p&gt;

&lt;p&gt;但是，精确计算到底要移动多少次往往是比较麻烦的（没人会愿意这么做），因此，还有一种方式是逐个词语移动光标。可以用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;移动到下一个单词开头，用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e&lt;/code&gt;移动到最近的单词的结尾。如果想反向移动到单词的开头，可以按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt;键。&lt;/p&gt;

&lt;p&gt;在 Vim 中还可以使用这些命令的大写版本，表示将除空格外的所有字符视为单词的一部分！这两套命令可让读者以两种不同的方式浏览文本。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Vim 中有两种单词对象：狭义单词（word）和广义单词（WORD）。在 Vim 的世界里，狭义单词指的是由空白字符（比如空格、制表符或换行符）分隔的字母、数字和下划线组成的序列，广义单词则是由空格分隔的任何非空字符组成的序列。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;比如前面的示例中的某一行代码，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/4a1e336c3ccfbf26.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;注意光标位置，它覆盖了&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add_animal&lt;/code&gt;的首字符。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;，光标会停在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add_animal&lt;/code&gt;的首字符上，而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;W&lt;/code&gt;则会跳到&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animal&lt;/code&gt;的首字符上。大写的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;W&lt;/code&gt;、&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt;将以空格分隔的非空字符序列视为单词，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;按键&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;行为&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;逐个狭义单词移动&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向前移动直到最近狭义单词的结尾&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;W&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;逐个广义单词移动&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向前移动直到最近广义单词的结尾&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向后移动到狭义单词开头&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向后移动到广义单词开头&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;下表则为每个命令的具体表现。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;按键&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;初始光标位置&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;光标最终位置&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/78e4c1c170b2436e.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/26f3f97825224943.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/23f21d0db76312ec.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;https://img30.360buyimg.com/ebookadmin/jfs/t1/93762/1/13064/1061/5e54e249Efc50843d/fcc0ac6f51e47c5c.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/c00795a5f911ea32.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/ac0d9f44367c4c80.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;W&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/0e1172cec7a714ea.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/78f4f0cc93a34a3c.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/4ab9098695b07a45.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/8c0c5bcfafb7b231.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/098d8811bb825e00.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/63a6d99d000f1c56.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;将这些命令与之前的方向命令结合起来，可以用更少的输入实现更快的移动。&lt;/p&gt;

&lt;p&gt;另外，按照段落移动也是很有用的。任意两个空行之间的文字被视为段落，这也意味着每个代码块可视为一个段落，如下图中所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/76e1c579fd52c6fb.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;函数&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add_animal&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;为两个不同的段落。在段落间向前移动的命令是结束大括号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;}&lt;/code&gt;，向后移动的命令是开始大括号&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{&lt;/code&gt;，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;行为&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;{&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向后移动一个段落&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;}&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;向前移动一个段落&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;在这些命令前面也可以加数字，这样，即使需要跳过多个段落，也可以一步到位。&lt;/p&gt;

&lt;p&gt;移动光标还有其他方式，上述只是一些重要的基础知识。第 2 章中会介绍更复杂的浏览方式。&lt;/p&gt;

&lt;h3 id=&quot;166-插入模式下的简单编辑&quot;&gt;1.6.6 　插入模式下的简单编辑&lt;/h3&gt;

&lt;p&gt;使用 Vim 的时候，通常希望在插入模式下花费尽可能少的时间（除非只负责写而不编辑）。因为大部分文本操作涉及编辑，所以本节将关注于这一部分。&lt;/p&gt;

&lt;p&gt;前面已经提到过，进入插入模式的命令为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt;。除此之外，还有其他方式可以进入插入模式。很多时候，需要对一部分文字进行替换，实现这个功能的方式是&lt;strong&gt;修改命令&lt;/strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c&lt;/code&gt;。通过&lt;strong&gt;修改命令&lt;/strong&gt;读者可以在删除一部分文字后立刻进入插入模式。&lt;strong&gt;修改命令&lt;/strong&gt;是一个复合命令，即它后面必须指定其他命令，用于告诉 Vim 修改哪一部分。读者可以将&lt;strong&gt;修改命令&lt;/strong&gt;与前面介绍过的任何移动命令组合起来使用，可参考下表中的示例。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;执行前&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;执行后&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cw&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/0bc8a8a41501f0f2.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/70ad7f5bc76915f9.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c3e&lt;/code&gt;（逗号视为一个词）&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/28f757ad110d05b6.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/248b91d89520fef9.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cb&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/7e9464f721517aef.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/5445472be0c815d4.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c4l&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/f501654aed005289.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/ab0c91768967c98b.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cW&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/f88430e6b623d551.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/6fd3b9b9fc4bbe7d.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
  &lt;p&gt;其中有一个奇怪的例外，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cw&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ce&lt;/code&gt;的行为类似，这是 Vim 的前身 Vi 的历史遗留问题。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;在掌握了更复杂的移动命令之后，也可以将它们与修改命令组合起来，实现快速的无缝编辑。本文后续还会介绍一些 Vim 插件，它们会重新实现修改命令，从而支持更强大的编辑功能，比如修改括号里的文字或直接替换引号类型。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;所有这些例子都遵循&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;命令&amp;gt; &amp;lt;数字&amp;gt; &amp;lt;移动或一个文本对象&amp;gt;&lt;/code&gt;这样的语法结构，可以将数字放在命令之前或之后。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;若想将&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;farm = add_animal(farm, animal)&lt;/code&gt;修改为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;farm = add_animal (farm, creature)&lt;/code&gt;，可以依次执行下表中列出的命令。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;代码行&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;行为&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;![(/img/in-post/2021-05-12-vim/d7cc0c65d023b315.png)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;将光标置于行首&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/019ee6c1a95e5280.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3W&lt;/code&gt;让光标跳过广义单词到达&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animal&lt;/code&gt;的首字母&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/72dae421460c9e96.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cw&lt;/code&gt;删除单词&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animal&lt;/code&gt;，然后立刻进入插入模式&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/1a3b1f0c58e875ca.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;creature&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/f0f5149752e60307.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;按 Esc 键回到正常模式&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;不过，有时候用户可能只想删除文字，而不想插入任何东西，命令&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt;可以实现这个功能。它表示删除（delete）的意思，其行为类似于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c&lt;/code&gt;，只不过这时候的&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;w&lt;/code&gt;和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;e&lt;/code&gt;的行为会标准得多，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;执行之前&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;执行之后&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dw&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/e195a0defa0fc1a1.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/18feeabe57afba1e.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d3e&lt;/code&gt;（逗号算一个单词）&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/a06fab93e4b9bd5d.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/99c72d293e88fb62.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;db&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/7567f702b3766c54.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/ea8f661f276f598b.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d4l&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/5b2265031461704c.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/34d4dd2094faf01d.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dW&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/ddd595c544ea88ed.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/5e842b7c9aa59209.png&quot; alt=&quot;&quot; /&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;还有两个更好的快捷命令用于修改或删除一整行，如下表所示。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;命令&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;行为&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cc&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;清除整行，然后进入插入模式。保持当前的缩进水平，这在编程时很有用&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dd&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;删除整行&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;比如，对于下1图中的代码片断，通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dd&lt;/code&gt;命令，可以移除整行，并得到下2图中的结果。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/b16e3cc9549e2be8.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/e79ee4a5a7927d5d.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;但如果使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cc&lt;/code&gt;命令删除该行，则会保留原来的缩进并进入插入模式，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/7eb6c589ce060bfe.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;如果读者在选择正确的光标移动命令时存在困难，也可以用可视（visual）模式来选择待修改的文本。按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v&lt;/code&gt;键可进入可视模式，然后通过常用的光标移动命令调整选择的文本。一旦选择完毕，就可以运行相应的命令（如用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;c&lt;/code&gt;键来修改或用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d&lt;/code&gt;键来删除）。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;167-持久性的撤销和重复&quot;&gt;1.6.7 　持久性的撤销和重复&lt;/h3&gt;

&lt;p&gt;和任何其他编辑器一样，Vim 也记录了每一步操作。按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;u&lt;/code&gt;键可以撤销最后一次操作，而&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + r&lt;/code&gt;组合键则可以重做此操作。&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;欲了解关于 Vim 撤销树的更多内容（Vim 的撤销历史记录不是线性的！），以及如何浏览这些历史记录，请参考第 4 章。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Vim 还支持在不同会话之间持久保存撤销历史，从而允许撤销几天前的操作。&lt;/p&gt;

&lt;p&gt;可以通过在&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;中进行如下设置来启用持久性撤销。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;set undofile
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;不过，这会在系统中为每个被编辑过的文件保留一个撤销历史记录文件，显得有些混乱。也可以将这些文件保存在同一个目录中，配置如下所示。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&quot; 为所有文件设置持久性撤销
set undofile
if !isdirectory(&quot;$HOME/.vim/undodir&quot;)
  call mkdir(&quot;$HOME/.vim/undodir&quot;, &quot;p&quot;)
endif
set undodir=&quot;$HOME/.vim/undodir&quot;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;对于 Windows 操作系统，将上述设置中的目录换成&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%USERPROFILE%_vim&lt;/code&gt;。需要注意，Windows 下的配置文件是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_vimrc&lt;/code&gt;，而不是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;168-通过help阅读-vim-手册&quot;&gt;1.6.8 　通过&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;阅读 Vim 手册&lt;/h3&gt;

&lt;p&gt;Vim 提供了一个学习工具&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;命令，其界面如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/e7ae3d32f745d8af.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Vim 手册中附带了大量的资源和教程。通过翻页键（PageUp 和 PageDown）可以浏览手册的内容（注意，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + b&lt;/code&gt;组合键和&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + f&lt;/code&gt;组合键也能起到翻页的效果），信息极其丰富。&lt;/p&gt;

&lt;p&gt;如果读者使用 Vim 时遇到问题，或者希望深入了解某个命令，可尝试使用&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;（其缩略版为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:h&lt;/code&gt;）来搜索这个命令。比如，读者可以搜索一下&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cc&lt;/code&gt;。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;:h cc
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;下图中的帮助信息显示了这条命令的运行方式，以及不同选项和设置是如何影响它的（如 autoindent 设置可保持缩进）。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/5ac787e825abfbc7.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;命令可用于浏览所有这些帮助文件。在阅读帮助文件时会发现，某些词是高亮显示的。它们是标签，即可用于&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;命令的关键字。不过，不是每个标签名都很直观。如果想知道如何在 Vim 中搜索一个字符串，用户可能会尝试使用如下命令。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;:h search
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;然而，输入这条命令后进入了表达式评估（expression evaluation）的页面，这并不是读者想要的，如下图所示。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/83034cc0c6555d52.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;为找到正确的词条，输入&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:h search&lt;/code&gt;（先不要按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Enter&lt;/code&gt;键），然后按&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ctrl + D&lt;/code&gt;组合键。这时会得到一个包含字符&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;search&lt;/code&gt;的标签列表。其中一项为&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;search-commands&lt;/code&gt;，这正是读者需要的。接下来继续补充命令行。&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;:h search-commands
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;得到如下图所示的帮助页面，这正是预期的结果。&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-12-vim/22dcf55dc2726338.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;关于搜索功能，读者可以在帮助页面（或在 Vim 中打开的任何文件）中输入“&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/关键字&lt;/code&gt;”进行正向搜索，或输入“&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?关键字&lt;/code&gt;”进行反向搜索。欲了解更多关于搜索操作的内容，请参考第 2 章。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;任何时候都不要忘记使用 Vim 的帮助系统，特别是有疑问或希望更好地理解 Vim 的行为时。&lt;/p&gt;

&lt;h2 id=&quot;17-小结&quot;&gt;1.7 　小结&lt;/h2&gt;

&lt;p&gt;原来的 Vi 版本是针对远程终端开发出来的，那时的带宽和网速都有限。但正是这些限制使 Vi 的文本编辑流程变得高效而专业，从而演变为如今的 Vim（改进版 Vi，Vi Improved）的核心。&lt;/p&gt;

&lt;p&gt;本章介绍了如何在主流平台上安装和更新 Vim，以及它的图形界面版本 gVim（介绍了太多方法，有些可能根本就不需要）。&lt;/p&gt;

&lt;p&gt;然后介绍了如何通过修改&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.vimrc&lt;/code&gt;文件来配置 Vim，这个过程在今后可能会反复进行，因为读者需要根据自己的需求定制这个编辑器。&lt;/p&gt;

&lt;p&gt;另外，还介绍了处理文件、在 Vim 中移动光标和修改内容等基本操作。Vim 中的文本对象的概念（字母、单词和段落）和复合命令（如&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;d2w&lt;/code&gt;会删除两个单词）可以帮助读者做出精确的文本操作。&lt;/p&gt;

&lt;p&gt;如果读者能从本章中学会一件事，那一定是&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:help&lt;/code&gt;。Vim 内置的帮助系统极其详细，它几乎可以回答所有关于 Vim 的问题。&lt;/p&gt;
</description>
        <pubDate>Wed, 19 May 2021 14:26:31 +0000</pubDate>
        <link>https://blog.bojin.co/2021/05/19/vim/</link>
        <guid isPermaLink="true">https://blog.bojin.co/2021/05/19/vim/</guid>
        
        <category>笔记</category>
        
        <category>教程</category>
        
        <category>Vim</category>
        
        <category>转载</category>
        
        
      </item>
    
      <item>
        <title>如何使用Markdown撰写文档</title>
        <description>&lt;h2 id=&quot;markdown&quot;&gt;Markdown&lt;/h2&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;a href=&quot;https://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;是在 2004 由约翰·格鲁伯（John Gruber）创建的一种轻量级标记语言，它允许人们使用易读易写的纯文本格式编写文档。
&lt;a href=&quot;https://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;编写的文档可以导出 HTML 、Word、图像、PDF、Epub 等多种格式的文档。
&lt;a href=&quot;https://daringfireball.net/projects/markdown/&quot;&gt;Markdown&lt;/a&gt;编写的文档后缀为 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.md&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.markdown&lt;/code&gt;。&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3 id=&quot;markdown-应用&quot;&gt;Markdown 应用&lt;/h3&gt;

&lt;p&gt;Markdown 能被使用来撰写电子书，如：Gitbook。&lt;/p&gt;

&lt;p&gt;当前许多网站都广泛使用 Markdown 来撰写帮助文档或是用于论坛上发表消息。例如：GitHub、简书、reddit、Diaspora、Stack Exchange、OpenStreetMap 、SourceForge等。&lt;/p&gt;

&lt;h3 id=&quot;markdown标题基础语法&quot;&gt;Markdown标题基础语法&lt;/h3&gt;

&lt;h4 id=&quot;标题--title&quot;&gt;标题 | Title&lt;/h4&gt;

&lt;p&gt;Markdown 标题有两种格式。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. 使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;=&lt;/code&gt; 和 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; 标记一级和二级标题&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gu&quot;&gt;这是H1的标题
===========
&lt;/span&gt;
&lt;span class=&quot;gh&quot;&gt;这是H2的标题
-----------
&lt;/span&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_title1.png&quot; alt=&quot;title 效果&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. 使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; 标记&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; 号可表示 1-6 级标题，一级标题对应一个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; 号，二级标题对应两个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&lt;/code&gt; 号，以此类推。&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gh&quot;&gt;# 一级标题&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;## 二级标题&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;### 三级标题&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;#### 四级标题&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;##### 五级标题&lt;/span&gt;

&lt;span class=&quot;gu&quot;&gt;###### 六级标题&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_title2.png&quot; alt=&quot;title 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;段落--paragraph&quot;&gt;段落 | Paragraph&lt;/h4&gt;

&lt;p&gt;Markdown 段落没有特殊的格式，可以直接编写文字就好，&lt;strong&gt;段落的换行是使用两个以上空格加上回车&lt;/strong&gt;。
&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_paragraph1.png&quot; alt=&quot;paragraph 效果&quot; /&gt;&lt;/p&gt;

&lt;p&gt;也可以在段落后面 &lt;strong&gt;使用一个空行来表示重新开始一个段落&lt;/strong&gt;。
&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_paragraph2.png&quot; alt=&quot;paragraph 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;斜体与加粗--phrase-emphasis&quot;&gt;斜体与加粗 | Phrase Emphasis&lt;/h4&gt;

&lt;p&gt;Markdown 使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*文本*&lt;/code&gt; 或 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_文本_&lt;/code&gt; 的方式来使用 &lt;strong&gt;斜体文本&lt;/strong&gt;，&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*文本*&lt;/code&gt; 或 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_文本_&lt;/code&gt; 的方式来使用 &lt;strong&gt;粗体文本&lt;/strong&gt;。&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;用法&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;效果&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*斜体文本*&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;em&gt;斜体文本&lt;/em&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_斜体文本_&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;em&gt;斜体文本&lt;/em&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;**粗体文本**&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;粗体文本&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__粗体文本__&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;粗体文本&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;***粗斜体文本***&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;&lt;em&gt;粗斜体文本&lt;/em&gt;&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;___粗斜体文本___&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;&lt;strong&gt;&lt;em&gt;粗斜体文本&lt;/em&gt;&lt;/strong&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;列表--list&quot;&gt;列表 | List&lt;/h4&gt;

&lt;p&gt;Markdown 支持无序列表和有序列表。&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;无序列表&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;无序列表使用 &lt;strong&gt;星号&lt;/strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*&lt;/code&gt; &lt;strong&gt;加号&lt;/strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt; 或是 &lt;strong&gt;减号&lt;/strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; 作为列表标记，这些标记后面要添加一个 &lt;strong&gt;空格&lt;/strong&gt;，然后再填写内容：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; 第一项
&lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; 第二项
&lt;span class=&quot;p&quot;&gt;*&lt;/span&gt; 第三项
&lt;span class=&quot;p&quot;&gt;
+&lt;/span&gt; 第一项
&lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; 第二项
&lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; 第三项
&lt;span class=&quot;p&quot;&gt;
-&lt;/span&gt; 第一项
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 第二项
&lt;span class=&quot;p&quot;&gt;-&lt;/span&gt; 第三项
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_list1.png&quot; alt=&quot;list 效果&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;有序列表&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;有序列表使用数字并加上 . 号来表示，如：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;1.&lt;/span&gt; 第一项
&lt;span class=&quot;p&quot;&gt;2.&lt;/span&gt; 第二项
&lt;span class=&quot;p&quot;&gt;3.&lt;/span&gt; 第三项
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_list2.png&quot; alt=&quot;list 效果&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;列表嵌套&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;列表嵌套只需在子列表中的选项前面添加四个空格即可:&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;1.&lt;/span&gt; 第一项：
&lt;span class=&quot;p&quot;&gt;    -&lt;/span&gt; 第一项嵌套的第一个元素
&lt;span class=&quot;p&quot;&gt;    -&lt;/span&gt; 第一项嵌套的第二个元素
&lt;span class=&quot;p&quot;&gt;2.&lt;/span&gt; 第二项：
&lt;span class=&quot;p&quot;&gt;    -&lt;/span&gt; 第二项嵌套的第一个元素
&lt;span class=&quot;p&quot;&gt;    -&lt;/span&gt; 第二项嵌套的第二个元素
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_list3.png&quot; alt=&quot;list 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;区块引用--blockquotes&quot;&gt;区块引用 | Blockquotes&lt;/h4&gt;

&lt;p&gt;Markdown 区块引用是在段落开头使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt; 符号 ，然后后面紧跟一个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;空格&lt;/code&gt; 符号：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gt&quot;&gt;&amp;gt;Hi, this is xxxbrian.&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt;Brian's Blog&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt;等青春轻飘的烟雾把少年的欢乐袅袅曳去，之后，我们就能取得一切值得吸取的东西。 ——普希金&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;另外区块是可以嵌套的，一个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt; 符号是最外层，两个 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;gt;&lt;/code&gt; 符号是第一层嵌套，以此类推：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gt&quot;&gt;&amp;gt; 最外层&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; &amp;gt; 第一层嵌套&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; &amp;gt; &amp;gt; 第二层嵌套&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;区块中使用列表&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gt&quot;&gt;&amp;gt; 区块中使用列表&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; 1. 第一项&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; 2. 第二项&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; + 第一项&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; + 第二项&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;&amp;gt; + 第三项&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;列表中使用区块&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; 第一项
&lt;span class=&quot;gt&quot;&gt;    &amp;gt; Brian's Blog&lt;/span&gt;
&lt;span class=&quot;gt&quot;&gt;    &amp;gt; Hi, this is xxxbrian.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;+&lt;/span&gt; 第二项
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_blockquotes.png&quot; alt=&quot;blockquotes 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;代码--code&quot;&gt;代码 | Code&lt;/h4&gt;

&lt;p&gt;如果是段落上的一个函数或片段的代码可以用 &lt;strong&gt;反引号&lt;/strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;`&lt;/code&gt;把它包起来&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;`代码`&lt;/code&gt;，例如想要显示: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;printf()&lt;/code&gt;函数&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;sb&quot;&gt;`printf()`&lt;/span&gt;函数
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;代码区块&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;代码区块使用 &lt;strong&gt;4 个空格&lt;/strong&gt; 或者一个 &lt;strong&gt;制表符（Tab 键）&lt;/strong&gt;。&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;    $(document).ready(function () {
        alert('RUNOOB');
    });
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;显示结果如下：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;$(document).ready(function () {
    alert('RUNOOB');
});
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;你也可以用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;/code&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt; &lt;/code&gt;` 包裹一段代码，并指定一种语言（也可以不指定）：&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;```javascript
$(document).ready(function () {
    alert('RUNOOB');
});
```
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;显示结果如下：&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ready&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;alert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;RUNOOB&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;'&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;超链接--link&quot;&gt;超链接 | Link&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;链接&lt;/strong&gt; 使用方法如下：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;链接名称&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;链接地址&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

或者

&lt;span class=&quot;nt&quot;&gt;&amp;lt;链接地址&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;例如：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;这是一个链接 &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Brian's Blog&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;https://bojin.co&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;这是一个链接 &lt;a href=&quot;https://bojin.co&quot;&gt;Brian’s Blog&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;直接使用链接地址&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;链接 &lt;span class=&quot;nv&quot;&gt;&amp;lt;https://bojin.co&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;链接 &lt;a href=&quot;https://bojin.co&quot;&gt;https://bojin.co&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;高级链接&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;我们可以通过变量来设置一个链接，变量赋值在文档末尾进行：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;这个链接用 1 作为网址变量 &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Google&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
这个链接用 bojin.co 作为网址变量 &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;xxxbrian&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;xxxbrian&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;http://www.google.com/&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;xxxbrian&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]:&lt;/span&gt; &lt;span class=&quot;sx&quot;&gt;https://bojin.co&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_link.png&quot; alt=&quot;link 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;图片--images&quot;&gt;图片 | Images&lt;/h4&gt;

&lt;p&gt;Markdown 图片语法格式如下：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;![&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;alt 属性文本&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;图片地址&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;p&quot;&gt;![&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;alt 属性文本&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;图片地址&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;&quot;可选标题&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;开头一个感叹号 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;接着一个方括号，里面放上图片的替代文字&lt;/li&gt;
  &lt;li&gt;接着一个普通括号，里面放上图片的网址，最后还可以用引号包住并加上选择性的 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;'title'&lt;/code&gt; 属性的文字。&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;使用实例：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;p&quot;&gt;![&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;xxxbrian 图标&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;sx&quot;&gt;https://raw.githubusercontent.com/xxxbrian/xxxbrian.blog/master/img/xxxbrian-192x192.png&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;&quot;xxxbrian&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;效果如下：
&lt;img src=&quot;https://raw.githubusercontent.com/xxxbrian.blog/master/img/xxxbrian-192x192.png&quot; alt=&quot;xxxbrian 图标&quot; title=&quot;xxxbrian&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;表格--sheet&quot;&gt;表格 | Sheet&lt;/h4&gt;

&lt;p&gt;Markdown 制作表格使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;|&lt;/code&gt; 来分隔不同的单元格，使用 &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt; 来分隔表头和其他行。&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;| 表头   | 表头   |
| ------ | ------ |
| 单元格 | 单元格 |
| 单元格 | 单元格 |
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;表格对齐&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-:&lt;/code&gt; 设置内容和标题栏居右对齐。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:-&lt;/code&gt; 设置内容和标题栏居左对齐。&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;:-:&lt;/code&gt; 设置内容和标题栏居中对齐。&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;| 左对齐 | 右对齐 | 居中对齐 |
| :----- | -----: | :------: |
| 单元格 | 单元格 |  单元格  |
| 单元格 | 单元格 |  单元格  |
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;img src=&quot;/img/in-post/2021-05-09-how-to-use-markdown/markdown_sheet.png&quot; alt=&quot;sheet 效果&quot; /&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h4 id=&quot;转义--backslash-escapes&quot;&gt;转义 | Backslash Escapes&lt;/h4&gt;

&lt;p&gt;Markdown 使用了很多特殊符号来表示特定的意义，如果需要显示特定的符号则需要使用转义字符，Markdown 使用反斜杠转义特殊字符：&lt;/p&gt;

&lt;div class=&quot;language-markdown highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;gs&quot;&gt;**文本加粗**&lt;/span&gt; 
&lt;span class=&quot;se&quot;&gt;\*\*&lt;/span&gt; 正常显示星号 &lt;span class=&quot;se&quot;&gt;\*\*&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Markdown 支持以下这些符号前面加上反斜杠来帮助插入普通的符号：&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;table class=&quot;rouge-table&quot;&gt;&lt;tbody&gt;&lt;tr&gt;&lt;td class=&quot;rouge-gutter gl&quot;&gt;&lt;pre class=&quot;lineno&quot;&gt;1
2
3
4
5
6
7
8
9
10
11
12
&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;rouge-code&quot;&gt;&lt;pre&gt;\   反斜线
`   反引号
*   星号
_   下划线
{}  花括号
[]  方括号
()  小括号
#   井字号
+   加号
-   减号
.   英文句点
!   感叹号
&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Wed, 19 May 2021 14:26:31 +0000</pubDate>
        <link>https://blog.bojin.co/2021/05/19/how-to-use-markdown/</link>
        <guid isPermaLink="true">https://blog.bojin.co/2021/05/19/how-to-use-markdown/</guid>
        
        <category>笔记</category>
        
        <category>教程</category>
        
        <category>Markdown</category>
        
        
      </item>
    
  </channel>
</rss>
