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