Vim 起步的五个技巧
vim vi Vimtutor Vimium
多年来，我一直想学 Vim。如今 Vim 是我最喜欢的 Linux 文本编辑器，也是开发者和系统管理者最喜爱的开源工具。我说的学习，指的是真正意义上的学习。想要精通确实很难，所以我只想要达到熟练的水平。我使用了这么多年的 Linux ，我会的也仅仅只是打开一个文件，使用上下左右箭头按键来移动光标，切换到插入模式，更改一些文本，保存，然后退出。


![](/data/attachment/album/201608/02/134516tqqhgihbb6sh182b.jpg)


但那只是 Vim 的最最基本的操作。我的技能水平只能让我在终端使用 Vim 修改文本，但是它并没有任何一个我想象中强大的文本处理功能。这样我完全无法用 Vim 发挥出胜出 Pico 和 Nano 的能力。


所以到底为什么要学习 Vim？因为我花费了相当多的时间用于编辑文本，而且我知道还有很大的效率提升空间。为什么不选择 Emacs，或者是更为现代化的编辑器例如 Atom？因为 Vim 适合我，至少我有一丁点的使用经验。而且，很重要的一点就是，在我需要处理的系统上很少碰见没有装 Vim 或者它的弱化版（Vi）。如果你有强烈的欲望想学习对你来说更给力的 Emacs，我希望这些对于 Emacs 同类编辑器的建议能对你有所帮助。


花了几周的时间专注提高我的 Vim 使用技巧之后，我想分享的第一个建议就是必须使用它。虽然这看起来就是明知故问的回答，但事实上它比我所预想的计划要困难一些。我的大多数工作是在网页浏览器上进行的，而且每次我需要在浏览器之外打开并编辑一段文本时，就需要避免下意识地打开 Gedit。Gedit 已经放在了我的快速启动栏中，所以第一步就是移除这个快捷方式，然后替换成 Vim 的。


为了更好的学习 Vim，我尝试了很多。如果你也正想学习，以下列举了一些作为推荐。


### Vimtutor


通常如何开始学习最好就是使用应用本身。我找到一个小的应用叫 Vimtutor，当你在学习编辑一个文本时它能辅导你一些基础知识，它向我展示了很多我这些年都忽视的基础命令。Vimtutor 一般在有 Vim 的地方都能找到它，如果你的系统上没有 Vimtutor，Vimtutor 可以很容易从你的包管理器上安装。


### GVim


我知道并不是每个人都认同这个，但就是它让我从使用终端中的 Vim 转战到使用 GVim 来满足我基本编辑需求。反对者表示 GVim 鼓励使用鼠标，而 Vim 主要是为键盘党设计的。但是我能通过 GVim 的下拉菜单快速找到想找的指令，并且 GVim 可以提醒我正确的指令然后通过敲键盘执行它。努力学习一个新的编辑器然后陷入无法解决的困境，这种感觉并不好受。每隔几分钟读一下 man 出来的文字或者使用搜索引擎来提醒你该用的按键序列也并不是最好的学习新事物的方法。


### 键盘表


当我转战 GVim，我发现有一个键盘的“速查表”来提醒我最基础的按键很是便利。网上有很多这种可用的表，你可以下载、打印，然后贴在你身边的某一处地方。但是为了我的笔记本键盘，我选择买一沓便签纸。这些便签纸在美国不到 10 美元，当我使用键盘编辑文本，尝试新的命令的时候，可以随时提醒我。


![vim cheat sheet](/data/attachment/album/201608/02/140344kj8jijivwgjtqv74.gif)


### Vimium


上文提到，我工作都在浏览器上进行。其中一条我觉得很有帮助的建议就是，使用 [Vimium](https://github.com/philc/vimium) 来用增强使用 Vim 的体验。Vimium 是 Chrome 浏览器上的一个开源插件，能用 Vim 的指令快捷操作 Chrome。我发现我只用了几次使用快捷键切换上下文，就好像比之前更熟悉这些快捷键了。同样的扩展 Firefox 上也有，例如 [Vimerator](http://www.vimperator.org/)。


![Vimium](/data/attachment/album/201608/02/140347z67x6p0ic83xzi6q.png)


### 其它人


毫无疑问，最好的学习方法就是求助于在你之前探索过的人，让他给你建议、反馈和解决方法。


如果你住在一个大城市，那么附近可能会有一个 Vim meetup 小组，或者还有 Freenode IRC 上的 #vim 频道。#vim 频道是 Freenode 上最活跃的频道之一，那上面可以针对你个人的问题来提供帮助。听上面的人发发牢骚或者看看别人尝试解决自己没有遇到过的问题，仅仅是这样我都觉得很有趣。




---


那么，现在怎么样了？到现在为止还不错。为它所花的时间是否值得就在于之后它为你节省了多少时间。但是当我发现一个新的按键序列可以来跳过词，或者一些相似的小技巧，我经常会收获意外的惊喜与快乐。每天我至少可以看见，一点点的回报，正在逐渐配得上当初的付出。


![Vim Advantures](/data/attachment/album/201608/02/134707zhki6hnqvpddpsff.png)


学习 Vim 并不仅仅只有这些建议，还有很多。我很喜欢指引别人去 [Vim Advantures](http://vim-adventures.com/)，它是一种使用 Vim 按键方式进行移动的在线游戏。而在另外一天我在 [Vimgifts.com](http://vimgifs.com/) 发现了一个非常神奇的虚拟学习工具，那可能就是你真正想要的：用一个小小的 gif 动图来描述 Vim 操作。


你有花时间学习 Vim 吗？或者是任何需要大量键盘操作的程序？那些经过你努力后掌握的工具，你认为这些努力值得吗？效率的提高有没有达到你的预期？分享你们的故事在下面的评论区吧。




---


via: <https://opensource.com/life/16/7/tips-getting-started-vim>


作者：[Jason Baker](https://opensource.com/users/jason-baker) 译者：[maywanting](https://github.com/maywanting) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
For years, I've wanted to learn [Vim](https://en.wikipedia.org/wiki/Vim_(text_editor)), now my preferred Linux text editor and a favorite open source tool among developers and system administrators. And when I say learn, I mean *really* learn. *Master* is probably too strong a word, but I'd settle for advanced proficiency. For most of my years using Linux, my skillset included the ability to open a file, use the arrow keys to navigate up and down, switch into insert mode, change some text, save, and exit.

But that's like minimum-viable-Vim. My skill level enabled me edit text documents from the terminal, but hasn't actually empowered me with any of the text-editing super powers I've always imagined were possible. And it didn't justify using Vim over the totally capable Pico or Nano.

So why learn Vim at all? Because I do spend an awful lot of time editing text, and I know I could be more efficient at it. And why not Emacs, or a more modern editor like Atom? Because Vim works for me, and at least I have *some* minimal experience in it. And perhaps, importantly, because it's rare that I encounter a system that I'm working on which doesn't have Vim or it's less-improved cousin (vi) available on it already. If you've always had a desire to learn Emacs, more power to you—I hope the Emacs-analog of these tips will prove useful to you, too.

A few weeks in to this concentrated effort to up my Vim-use ability, the number one tip I have to share is that you actually must use the tool. While it seems like a piece of advice straight from Captain Obvious, I actually found it considerably harder than I expected to stay in the program. Most of my work happens inside of a web browser, and I had to untrain my trigger-like opening of Gedit every time I needed to edit a block of text outside of a browser. Gedit had made its way to my quick launcher, and so step one was removing this shortcut and putting Vim there instead.

I've tried a number of things that have helped me learn. Here's a few of them I would recommend if you're looking to learn as well.

## Vimtutor

Sometimes the best place to get started isn't far from the application itself. I found Vimtutor, a tiny application that is basically a tutorial in a text file that you edit as you learn, to be as helpful as anything else in showing me the basics of the commands I had skipped learning through the years. Vimtutor is typically found everywhere Vim is, and is an easy install from your package manager if it's not already on your system.

## GVim

I know not everyone will agree with this one, but I found it useful to stop using the version of Vim that lives in my terminal and start using GVim for my basic editing needs. Naysayers will argue that it encourages using the mouse in an environment designed for keyboards, but I found it helpful to be able to quickly find the command I was looking for in a drop-down menu, reminding myself of the correct command, and then executing it with a keyboard. The alternative was often frustration at the inability to figure out how to do something, which is not a good feeling to be under constantly as you struggle to learn a new editor. No, stopping every few minutes to read a man page or use a search engine to remind you of a key sequence is not the best way to learn something new.

## Keyboard maps

Along with switching to GVim, I also found it handy to have a keyboard "cheat sheet" handy to remind me of the basic keystrokes. There are many available on the web that you can download, print, and set beside your station, but I opted for buying a set of stickers for my laptop keyboard. They were less than ten dollars US and had the added bonus of being a subtle reminder every time I used the laptop to at least try out one new thing as I edited.

## Vimium

As I mentioned, I live in the web browser most of the day. One of the tricks I've found helpful to reinforce the Vim way of navigation is to use [Vimium](https://github.com/philc/vimium), an open source extension for Chrome that makes Chrome mimick the shortcuts used by Vim. I've found the fewer times I switch contexts for the keyboard shortcuts I'm using, the more likely I am to actually use them. Similar extensions, like [Vimerator](http://www.vimperator.org/), exist for Firefox.

## Other human beings

Without a doubt, there's no better way to get help learning something new than to get advice, feedback, and solutions from other people who have gone down a path before you.

If you live in a larger urban area, there might be a Vim meetup group near you. Otherwise, the place to be is the #vim channel on Freenode IRC. One of the more popular channels on Freenode, the #vim channel is always full of helpful individuals willing to offer help with your problems. I find it interesting just to listen to the chatter and see what sorts of problems others are trying to solve to see what I'm missing out on.

And so what to make of this effort? So far, so good. The time spent has probably yet to pay for itself in terms of time saved, but I'm always mildly surprised and amused when I find myself with a new reflex, jumping words with the right keypress sequence, or some similarly small feat. I can at least see that every day, the investment is bringing itself a little closer to payoff.

These aren't the only tricks for learning Vim, by far. I also like to point people towards [Vim Adventures](http://vim-adventures.com/), an online game in which you navigate using the Vim keystrokes. And just the other day I came across a marvelous visual learning tool at [Vimgifs.com](http://vimgifs.com/), which is exactly what you might expect it to be: illustrated examples with Vim so small they fit nicely in a gif.

Have you invested the time to learn Vim, or really, any program with a keyboard-heavy interface? What worked for you, and, did you think the effort was worth it? Has your productivity changed as much as you thought it would? Let's share stories in the comments below.

## 6 Comments