vim block vim_我如何学会爱Vim

vim block vim

by Sanchit Gera

通过Sanchit Gera

我如何学会爱Vim (How I learned to love Vim)

I’ve had a bitter-sweet relationship with Vim for a long time.

我与Vim有一段苦甜的恋情。

Over the last couple of years, I tried to learn Vim on several occasions. Each time, I ended up abandoning it. Instead, I would resort to my ‘primary’ text editor (usually Atom).

在过去的几年中,我尝试过几次学习Vim。 每次,我最终都放弃了它。 相反,我会求助于我的“主要”文本编辑器(通常 原子 )。

But for a couple of weeks, I found myself unable to use Atom. This was due to an obscure connectivity issue. This made my setup completely useless over remote connections.

但是几个星期后,我发现自己无法使用Atom。 这是由于模糊的连接问题 。 这使我的设置完全无法通过远程连接使用。

After going through the five stages of grief, I decided to bite the bullet and try (again) to learn Vim. This time I forced myself to use Vim, and Vim alone.

在经历了悲伤的五个阶段之后,我决定忍痛忍受,并尝试(再次)学习Vim。 这次我强迫自己使用Vim,并且单独使用Vim。

I know — I could have easily switched to a more intuitive editor such as Sublime. Or I could even have used a fully fledged IDE like IntelliJ.

我知道—我可以很容易地切换到更直观的编辑器,例如Sublime 。 或者我什至可以使用像IntelliJ这样的成熟IDE。

Instead, I figured “what the hell”. Here are some of the things I learnt.

相反,我想到了“到底是什么”。 这是我学到的一些东西。

学习基础 (Learning the basics)

In case it’s new to you, Vim is a seemingly archaic text editor. Its roots go back to a program call Vi, which appeared during the 1970s.

万一您不熟悉它,Vim是一个看似古老的文本编辑器。 它的起源可以追溯到1970年代出现的Vi程序。

Part of Vim’s appeal — and annoyance — is due to the fact it is designed to work entirely with your keyboard. After all, point-and-click GUIs weren’t really a thing back when Vi was conceived.

Vim的吸引力之一(也是令人讨厌的部分原因)是因为它旨在完全与您的键盘一起使用。 毕竟,在构思Vi时,点击式GUI并不是真正的东西。

Vim instead uses modes. There are two main modes that can be used:

Vim改为使用mode 。 可以使用两种主要模式:

  • Normal mode: this is the mode you use when you are navigating your files, or editing/manipulating them. This is mode for doing anything that does not involve typing new content. Most Vim commands are entered while in this mode.

    普通模式:这是您浏览文件或编辑/操作文件时使用的模式。 这是用于执行不涉及键入新内容的任何操作的模式。 在此模式下,大多数Vim命令都被输入。
  • Insert mode: insert mode allows the input of new text. In this mode, Vim behaves more like a ‘normal’ text editor, such as Atom or Sublime. Minus the use of a mouse, of course.

    插入模式:插入模式允许输入新文本。 在这种模式下,Vim的行为更像是“普通”文本编辑器,例如Atom或Sublime。 当然,要减去鼠标的使用。

Other modes exist in Vim too. One example is the visual mode, for selecting large chunks of text. Typically, these modes are used much less frequently.

Vim中也存在其他模式。 一个示例是可视模式,用于选择大块文本。 通常,这些模式的使用频率要低得多。

Vim is normally used inside a Terminal emulator. However, standalone distributions exist. It is available on virtually all Unix and Linux systems. Vim’s grandfather, Vi, is part of the UNIX specification. It therefore comes preinstalled on all conforming systems.

Vim通常在终端仿真器内使用。 但是,存在独立发行版。 几乎所有Unix和Linux系统都可以使用它。 Vim的祖父Vi是UNIX规范的一部分。 因此,它预先安装在所有符合标准的系统上。

可组合性 (Composability)

‘Composability’ is largely what makes Vim different to other editors. It gives Vim its own special language.

Vim与其他编辑器的不同之处在于“可组合性”。 它为Vim提供了自己的特殊语言。

It introduces the notion of nouns and verbs in the context of text editing and manipulation.

它在文本编辑和操作的上下文中介绍了名词动词的概念。

Verbs describe actions that you can take (such as delete, change, move).

动词描述了您可以执行的操作(例如删除,更改,移动)。

Nouns describe what is being acted upon (usually words, lines or places within the text).

名词描述所采取的行动(通常是文字中的单词,线条或位置)。

Some of the nouns/verbs commonly used include:

常用的一些名词/动词包括:

Verbs d: deletec: change (overwrite)y: yank (copy)>: indent<: unindent
Actionsh,j,k,l: left, down, up, rightw: next wordb: previous word0: start of line$: end of linei: inside (excluding the following character)a: around (including the encasing characters)

This list is non-exhaustive. There are tons and tons of key-bindings available. But you can achieve a lot with only the very basic ones. The idea is to chain together combinations of nouns, verbs and occasionally numbers. This allows you to create distinct actions to manipulate the text as needed.

此列表并不详尽。 有成千上万的键绑定可用。 但是,只有非常基本的内容,您才能取得很多成就。 这个想法是将名词,动词和偶然的数字组合在一起。 这使您可以创建不同的动作 根据需要操纵文本。

For example, to delete a word you type in the key combination dw.

例如,d elete A, ORD您在组合键键入dw

To delete 2 words from the current position, you type in d2w.

d elete2 瓦特从当前位置ORDS,你输入d2w

To delete from the current position all the way to the end of the line, you type in d$.

要从当前位置一直删除到行尾,请输入d$

To delete everything inside a pair of parentheses, you would type di(. And on it goes.

d elete一切, n面一对括号,您可以键入di( 。而就不言而喻。

This method of working might not seem worth the hassle. But if you force yourself to use the combinations every day, they will become second nature. After a certain point, the speed you gain by reducing the number of keystrokes required to make a certain edit is absolutely thrilling. More on that next.

这种工作方法似乎不值得麻烦。 但是,如果您强迫自己每天使用这些组合,它们将成为第二天性。 在特定的点之后,通过减少进行特定编辑所需的击键次数而获得的速度绝对令人兴奋。 接下来的更多内容。

Vim会上瘾 (Vim is addictive)

Yes, I know. It’s a cliché. But bear with me.

是的我知道。 这是陈词滥调。 但是,请忍受我。

Vim has a notorious learning curve. But once you get past the stage where you are constantly cursing your computer screen, using Vim is actually quite fun.

Vim有一个臭名昭著的学习曲线。 但是,一旦您走过了不断咒骂计算机屏幕的阶段,使用Vim实际上会很有趣。

Learning to use Vim’s cryptic commands lets you fly through the file editing process. After a while, it almost feels wrong to lift your fingers away from the home row on the keyboard, or even to use the mouse!

学习使用Vim的加密命令可以使您快速完成文件编辑过程。 一段时间后,将手指从键盘上的主行上抬起甚至使用鼠标几乎感觉不对!

After only one month, I find myself missing Vim’s navigation system and other shortcuts while using my computer regularly.

仅一个月后,我发现自己在定期使用计算机时缺少Vim的导航系统和其他快捷方式。

In fact, at one point I considered experimenting with this extension to enable Vim keybindings while browsing the web. I know!

实际上,我曾经考虑过尝试使用该扩展程序在浏览Web时启用Vim键盘绑定。 我知道!

Fortunately, the programming community recognizes this. Most mainstream text editors have some way of enabling Vim keybindings. This puts ‘Vimmers’ out of their misery by giving them the best of both worlds.

幸运的是,编程社区认识到了这一点。 大多数主流的文本编辑器都有启用Vim绑定的某种方式。 通过为他们提供两全其美的选择,使“ Vimmers”摆脱了痛苦。

给Vim一个战斗的机会 (Giving Vim a fighting chance)

The key improving at Vim is to simply not use anything else. Instead, you should force yourself to do everything the Vim way.

Vim的关键改进是根本不使用其他任何东西。 相反,您应该强迫自己以Vim方式进行所有操作。

For example — when editing files in Vim, try not to resort to your old habits. Most people, when starting out, try to stay as far away from ‘normal mode’ as possible.

例如,在Vim中编辑文件时,请尽量不要诉诸旧习惯。 大多数人在开始时都尝试尽可能远离“正常模式”。

Instead, they try to spend as much time as they can in ‘insert mode’. In this mode, it is easy to feel more at home. It lets you get away with editing your file without learning anything new. But this is a mistake.

相反,他们尝试在“插入”上花费尽可能多的时间 模式'。 在这种模式下,很容易有宾至如归的感觉。 它使您无需学习任何新知识就可以轻松编辑文件。 但这是一个错误。

If you are genuinely interested in learning how to make Vim work for you, you have to put in some effort. This means taking the time to figure out the ‘right’ way to do something.

如果您真的有兴趣学习如何使Vim为您工作,则必须付出一些努力。 这意味着要花时间找出做事的“正确”方法。

If you find yourself repeating keystrokes over and over again to achieve any task, stop. It is likely there is a better way to do what you are trying to do.

如果发现自己反复重复击键以完成任何任务,请停止 。 可能有更好的方法来做您想做的事情。

Google it. Memorize it. Add it to your arsenal. It is far easier to learn new commands this way, compared to reading a list of commands and hoping you’ll need to use one of them.

谷歌一下。 记住。 将其添加到您的武器库。 与阅读命令列表并希望使用其中一个命令相比,用这种方法学习新命令要容易得多。

After a couple of days, you may develop an intuitive sense of when you are wasting keystrokes. Heed to your intuition.

几天后,您可能会感觉到浪费按键的时间。 注意您的直觉。

欣赏(?)现代编辑 (Appreciate (?) modern editors)

Another big reason many people shy away from Vim is the seemingly ‘barebones’ nature of it all.

许多人都不愿使用Vim的另一个重要原因是这一切看起来像“准系统”。

By default, Vim comes with no plugins or nice-to-have features. And what Vim considers to be a ‘nice-to-have’ feature is probably very different to what programmers used to modern IDEs would consider ‘nice-to-have’.

默认情况下,Vim没有插件或完善的功能。 Vim认为“必备”功能可能与习惯于现代IDE的程序员所认为的“必备”功能有很大不同。

Vim comes with barebones syntax highlighting (which is disabled by default). There is no line-numbering (again, this needs to be enabled separately).

Vim带有准系统语法突出显示(默认情况下处于禁用状态)。 没有行号(同样,需要单独启用)。

No surprise, then, that things such as:

那么,诸如此类的事情就不足为奇了:

  • default Git integration

    默认的Git集成
  • ‘complete-as-you-go’ code completion

    “按需完成”代码完成
  • automatic bracket completion

    自动完成括号
  • code snippets

    代码段
  • custom color schemes

    自定义配色方案

…do not come pre-installed with Vim.

…不要预装Vim。

This might seem like huge turn off — especially for programmers used to developing in powerful IDEs that do a lot of heavy lifting. Many come installed with a whole bunch of plugins and extensions designed specifically to make your workflow more efficient.

这似乎是一个巨大的挑战,特别是对于那些习惯于使用功能强大的IDE进行大量繁重开发工作的程序员而言。 其中许多安装有大量的插件和扩展程序,这些插件和扩展程序专门用于使您的工作流程更高效。

And there is some merit to this argument. Vim has its limitations.

这个论点有一些优点。 Vim有其局限性。

Yet on the flip-side — even though you appreciate what modern IDEs provide and the work that goes into building them — you also realize that most IDEs (and even modest editors such as Atom) bring with them a lot of bloat.

然而,另一方面,即使您欣赏现代IDE所提供的功能以及构建它们所要做的工作,您也意识到大多数IDE(甚至包括Atom这样的谦虚编辑器)也给他们带来了很多膨胀。

Advanced IDEs come jam-packed with features that are hardly used by average users.

高级IDE挤满了普通用户几乎不使用的功能。

Learning to use Vim effectively is partly an exercise in working out which plugins are absolutely critical to your productivity. The key is to build an editor uniquely suited to your needs and workflow.

学习有效地使用Vim在某种程度上是确定哪些插件对您的生产力至关重要的练习。 关键是要构建一个完全适合您的需求和工作流程的编辑器。

In many cases, using a fully-fledged IDE makes perfect sense. The advanced features may far outweigh any benefits you get from using Vim.

在许多情况下,使用成熟的IDE是很有意义的。 高级功能可能远远超过使用Vim所带来的任何好处。

But, this is something for you to figure out yourself.

但是,这是您要弄清楚自己的东西。

Despite its barebones nature, Vim has a thriving plugin ecosystem.

尽管Vim具有准系统性质,但它具有蓬勃发展的插件生态系统。

Vim has plugins for almost everything you can do with other editors. You just have to figure out which you need.

Vim具有几乎可以与其他编辑器一起使用的所有功能的插件。 您只需要弄清楚您需要什么。

Something that surprised me was how far I can go with just a handful of plugins. My Vim setup currently comprises of around five or six ‘essential’ add-ons. I don’t really feel like I’m missing out on anything.

让我感到惊讶的是,只有少数几个插件我能走多远。 我的Vim设置当前包含大约五个或六个“基本”加载项。 我真的不觉得我错过任何事情。

Vim is not perfect. And it is definitely not for everybody.

Vim并不完美。 绝对不适合所有人。

But at the very least, learn enough of Vim in case you accidentally open it and can’t figure out how to quit…! ;)

但是至少,要对Vim有足够的了解,以防万一您不小心打开了它而又不知道该如何退出 ……! ;)

翻译自: https://www.freecodecamp.org/news/how-i-learned-to-love-vim-ce3e058d57fb/

vim block vim

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值