七个高效的文本编辑习惯(以Vim为例)

论坛 期权论坛     
选择匿名的用户   2021-5-26 13:29   886   0
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 如果你花很多时间输入纯文本、写程序或HTML,那么通过高效地使用一个好的编辑器,你可以节省大部分时间。本文将提供指导和提示,让你更迅速地做这些工作,并且少犯错误。</p>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 本文用开源文本编辑器Vim(Vi IMproved)来演示如何高效编辑,本文方法同样适用于其他的编辑器。选择合适的编辑器,实际上是进行高效编辑的第一步。我们避免去<a href="http://blog.jobbole.com/24594/" rel="noopener noreferrer" style="border:0px; margin:0px; padding:0px; color:rgb(0,153,204)" target="_blank" title="开发人员眼中最好的代码编辑器">讨论哪个编辑器最适合</a>你,因为这个话题将占用太多篇幅。如果你不知道选用那个编辑器,或者你对目前使用的编辑器不满意,那就试试Vim;你将不会失望。</p>
<h3 align="center" style="border:0px; margin:-8px 0px 20px; padding:0px; font-size:20px; line-height:30px; font-family:Arial,sans-serif; color:rgb(51,51,51)"> 第1部分:编辑一个文件</h3>
<h3 align="center" style="text-align:left; border:0px; margin:-8px 0px 20px; padding:0px; line-height:30px; font-family:Arial,sans-serif; color:rgb(51,51,51)"> <span style="font-size:18px">1.快速移动</span></h3>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 大部分时间都花在阅读、检查错误和寻找正确的位置去工作,而不是插入新的文本或修改它。在文本内导航非常频繁,因此你应该学会如何迅速做到这一点。</p>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 很多时候,当你希望搜索一些已存在的文本,或在所有行里寻找某个用到的单词或短语时,你可以简单地使用搜索命令、模式去找到它。但是也有更智能的方法:</p>
<ul style="border:0px; margin:0px 0px 20px; padding:0px; font-size:14px; list-style-position:inside; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"><li style="border:0px; margin:0px; padding:0px">如果你看到一个特定的单词,并想搜索它出现的其他地方,就使用命令*。它会从光标下面定位找到这个单词,并且搜索下一个。</li><li style="border:0px; margin:0px; padding:0px">如果设置了“incsearch”选项,当你还在输入时,Vim将会显示第一个匹配模式的文本。这能迅速显示一个模式错误。</li><li style="border:0px; margin:0px; padding:0px">如果设置了“hlsearch”选项,Vim将用黄色背景高亮显示所有匹配的模式,让你对搜索命令的结果有个快速概览。它可以显示一个变量在程序代码哪个位置被使用。你甚至不需要移动光标去看匹配的文本。</li></ul>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 在结构化的文本中还有更多可能性快速移动。Vim有针对C(以及类似语言,如C&#43;&#43;和Java)程序的特定命令:</p>
<ul style="border:0px; margin:0px 0px 20px; padding:0px; font-size:14px; list-style-position:inside; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"><li style="border:0px; margin:0px; padding:0px">使用%从一个左括号跳转到与其配对的右括号,或从一个“#if”到配对的“#endif”。实际上%可以跳转到许多不同的匹配项目。它对检查if()和{}的结构完整性非常有用。</li><li style="border:0px; margin:0px; padding:0px">使用[{跳回当前代码块起始的“{”。</li><li style="border:0px; margin:0px; padding:0px">使用GD从变量的调用跳转到它的局部声明。</li></ul>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 当然还有更多的,重点是你需要知道这些命令。你也许认为不可能了解所有这些命令——有几百种不同的移动命令,有些简单,有些非常灵活——需要花费几个星期的训练去学会它们。然而,你不需要这样做。相反,你需要知道自己具体的编辑方式,并且只学习那些能让你的编辑更高效的命令。</p>
<p style="border:0px; margin-top:0px; margin-bottom:20px; padding-top:0px; padding-bottom:0px; font-size:14px; color:rgb(51,51,51); font-family:Arial,sans-serif; line-height:21px"> 三个基本步骤:</p>
<ol style="border:0px; margin:0px 0px 20px; padding:0px; font-size:14px; list-style-posi
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP