English 中文(简体)
学习Vim有什么好处?[已关闭]
原标题:
  • 时间:2009-02-27 23:27:07
  •  标签:
Locked. This question and its answers are locked because the question is off-topic but has historical significance. It is not currently accepting new answers or interactions.

作为一名程序员,我在键盘前花费了很多时间,这样做已经持续了大约12年。在所有这些时间里,有一件事情我从来没有习惯,那就是在编码时经常出现的烦人而几乎无意识的微小中断,这是由于一些最常见的代码编辑任务引起的。比如从不同行(甚至是同一行)简单的复制和粘贴,或者从当前位置向上或向下移动1或2行,需要太多的打字,或者涉及使用箭头键…当我想更进一步时,情况就更糟了——我最终使用了鼠标。现在想象一下,在笔记本电脑上出现相同的情景。

我一直考虑学习VIM,但需要掌握它的时间量总是让我想退缩。

我想听听那些学会了它并发现它成为了那些你无法离开的东西的人的看法。

在工作中,我使用VS2008、C#和R#,它们一起使编辑代码比以往更快、更容易,但即便如此,我仍然认为不用鼠标可能会更加愉快。

甚至连箭头键都不行。

最佳回答

我使用vi和vim已经有20年了,但我还在学习新的东西。

David Rayner的最佳Vim技巧网站是一个非常好的列表,但如果你对vim有一定的熟悉度,那么它可能会更有用。

我还想提到 ViEmu 网站,该网站提供了一些有关 vi/vim 技巧的重要信息,尤其是那篇文章“为什么那些疯子要使用 vi?”(档案版本)。

问题回答

我能没有它生活吗?很容易。

有用吗?是的。 (yǒu yòng ma? shì de.)

Reasons for Learning

  • vi 在所有 Unix 系统上都有保证存在,并且在大多数 Linux 系统上也存在。这种广泛覆盖使学习它变得非常有价值。

  • 使用vi进行sudo编辑要快得多:

    $ sudo vi translates to $ sudo vi in Chinese as it is technical terminology and does not require translation.

  • 此外,Gmail使用类似于Vi的命令进行选择和移动电子邮件!

你不需要成为一位大师。

只要努力学习。

The basics:

  • How to switch from command mode to insert mode i
  • How to switch from insert mode to command mode Esc
  • How to navigate up a line in command mode k
  • How to navigate down a line in command mode j
  • How to navigate left a character in command mode h
  • How to navigate right a character l
  • How to save a file :wEnter (write)
  • How to exit without saving (in command mode) :q!Enter
  • How to Undo u
  • How to Redo Ctrl+r
  • You can combine writing and quitting (in command mode): :wqEnter

从那时起,其余的都只会让你更快。

仅运行 vimtutor 就花了我30分钟,这已经足够让我熟悉vim了。这绝对是值得的。

如果您是一个经常编辑文本的程序员,那么学习一个严肃的文本编辑器非常重要。您学习哪个严肃的文本编辑器不是非常重要的,而且在很大程度上取决于您预计需要编辑的环境。

原因是这些编辑器已经高度优化,以便执行您将经常执行的任务。例如,请考虑将相同的文本位添加到每行的末尾。这在一个专业的文本编辑器中是微不足道的,但在其他情况下会非常繁琐。

通常认为Vim的杀手级功能是:A)它几乎可在您遇到的每个Unix上使用,B)您的手指很少需要离开主键行,这意味着您能够非常快速地编辑文本。即使编辑大型文件,它通常也非常快速轻便。

然而,有很多替代选择。当然,Emacs是最常见的例子,并且如果你真的深入研究它,它不仅仅是一个高级文本编辑器。经过多年的vim/gvim使用,我个人现在非常喜欢使用TextMate。

切换到任何其中一种的诀窍是强制自己以它们的预定方式使用它们。例如,在vim中,如果你手动执行了多步骤过程的每一步或者使用箭头键或鼠标,那么可能有更好的方法来完成它。停下你正在做的事情,查找一下。

如果你没有其他事情要做,那就学习vim和Emacs的基本导航控件,因为它们在各个地方都出现过。例如,在Mac OS的任何文本输入字段,大多数Unix shell,Eclipse等中都可以使用Emacs风格的控件。在less(1)命令、Slashdot、gmail等中都可以使用vim风格的控件。

玩得开心!

这肯定是值得努力的。

有一个明显的原因是,任何使用 Vi(m) 的人都会告诉你,还有两个人似乎从未提到的原因。

这是显而易见的一个:

  1. vi is at once ubiquitous and incredibly powerful, and by learning it once, you gain the ability to exercise that power on pretty much any computer that has a keyboard.

这些是学习 Vim 的较少为人知的原因:

  1. 这不需要你想象中的那么多精力。只需跑一遍Vim教程(在终端输入vimtutor,或在Windows下从开始菜单中的Vim文件夹运行),你就已经走上了掌握Vim的道路,而且一切都会变得轻松自如。在不到一周的午餐时间里,我就能在工作中使用Vim,而且完全没有减少生产力的迹象。

  2. 这很有!现在编辑文本对我来说就像玩游戏一样。我非常喜欢它——如果你想想的话,这相当荒谬。

学习也有两个很好的理由不要学习:

  1. 这很容易上瘾,并且你会发现自己希望在所有电脑操作中都能使用Vim命令,并在无法使用时咒骂。幸运的是,至少对于某些情况,有方法 可以解决 这个 问题

  2. 再说一遍,这是一种让人上瘾的体验。虽然你不会因为实际使用 Vim 而失去任何生产力,但你会浪费数小时寻找好的技巧,让你的 Vim 体验更加完美,并阅读 Stack Overflow 上的Vim 标签

学习vim或emacs确实值得。学习打字也是很值得的。在这两种情况下,原因是相同的:你的思维不再被将代码输入到屏幕的机械过程所打断。

关于如何开始,只需深入使用 vim 并将其用于一切。

附言:Emacs与vi之间的争论是无休止的。我已经使用Emacs了26年。如果我今天重新开始,我会学习vim,因为(a)它变得更好了,(b)有很少的修饰键(Ctl-Alt-V有人用吗)而且vim用户似乎受到的打字伤害要少得多。

通过学习16个键的含义,您可以获得vim的良好功能:ijkdbw9:q!%s / nN Esc。仅使用i:wq Esc即可完成最基本的要求。

你需要了解的前两个键是:Esc键让你进入命令模式(初始模式),i键让你进入插入模式(普通输入)。


储蓄需要

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase w then Enter

为了保存并退出,您需要

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase wq then Enter

为了不保存并强制退出,您需要

  1. get out of typing mode (Esc)
  2. type a colon :
  3. type lowercase q! then Enter

要了解更多,您可以在命令行上运行 vimtutor 。它是一堂中等长度、结构良好的课程。

超越 iEsc:只需 jkwbd3:%s/nN,您可以复制或超越一些 MS Word 的功能。

  1. b takes you back a word (Ctrl+)
  2. w takes you forward a word (Ctrl+)
  3. 9w takes you forward nine words
  4. db deletes the preceding word (Ctrl+Backspace)
  5. d3b deletes three preceding words
  6. 9j moves down 9 lines
  7. / ornithopter Enter takes you to the next instance of the word "ornithopter", then n and N to the next and previous occurrence of "ornithopter" respectively.
  8. :%s/confounded/dangfangled/ Enter substitutes every "confounded" with "dangfangled" (like find and replace all in MS Word)

任何一个都应该在“命令”模式 (Esc) 下运行,而不是插入模式 (i)。

我最近转向了VIM,我认为这是值得的。如果您需要“只是完成某些事情”,您始终可以保持插入模式,其中vim(大多数情况下)就类似于普通文本编辑器。

我注意到以前不煩惱的事情,比如伸手去按箭頭鍵,現在感覺不對且需要太多努力。這絕對減少了我的手部運動和滑鼠的使用,這對人體工程學和生產力都很有好處。

这取决于你想用VIM做什么。仅仅因为许多人离不开它而去学它是没有意义的。

当我在UNIX环境下工作时,我离不开它。即使在UNIX机器上没有安装VIM,我至少可以使用vi。你总是可以信赖它 - 即使机器不是你的(来自客户方)。 当我在UNIX环境下工作时,我不能没有它。即使UNIX机器上没有安装VIM,我至少可以使用vi。您总是可以依靠它 - 即使机器不属于您(来自客户)。

现在我使用C#进行编程,并主要在Windows环境下工作。我在我的计算机上安装了VIM ...但我不需要它。

评估一下你是否真的需要VIM,它是否能帮助你更好地完成工作流程。试一下,玩弄一下它。如果你认为你需要它,就坚持使用...学习曲线非常陡峭。

我学习了Vi是因为我不得不学。

我的疯狂老师强迫我们学习使用终端连接到AIX系统编程C语言。

这真的很痛苦,但是它是值得的。

今天,我只使用vi进行快速编辑或小型程序。

当我需要进行项目时,我更喜欢使用IDE。在我的情况下,IntelliJ idea非常擅长这项任务,因为我可以连续数小时编码而不必抓鼠标。

我不知道VS2008有多少快捷键,但如果它们能像Eclipse一样被发现,那么我认为你应该选择vi。

如果您不在IDE外编辑代码,并且您的IDE具有良好的快捷方式,那么您最好学习这些快捷方式,然后去学习vi。

请提供需要翻译的文本。

我用vi / vim超过25年。如果你已经知道一些命令行编辑器,那么也许你不需要学习vi / vim。但是,如果你不太熟悉任何其他命令行编辑器,学习vi / vim是值得的。在vi / vim中很容易用很少的努力就可以提高工作效率。

我现在基本上只使用VIM。

我曾经使用Vim编辑和VS编辑器进行调试。这可能看起来有点疯狂,但我发现Vi范例(宏、基于Home键的编辑等)对我的生产力有很大提升,所以在VS中编辑很痛苦。

多亏了Viemu,我不再需要进行频繁的切换了。这还不是完美的解决方案(代码补全有时不如原生vim那么优雅,宏录制也不完美),但它比不停地来回切换要好得多。

Vim的学习曲线可能有夸张的成分。我认为一旦你开始使用它,它就变得非常直觉。

我的工作逼迫我开始使用vim,现在它已经成为了我的第二天性。现在我的抱怨是关于那些没有vim仿真或插件的IDE。我注意到,在vim以外的环境中,Esc键已经成为了我的敌人。

我在Visual Studio中找了几个针对vi的模拟器:

http://code.google.com/p/vim-visual-studio/ :将此翻译成中文。

首先,良好的Vi(m)知识可以节省你在服务器遭受攻击时急于进行紧急配置文件编辑所需的时间。它可以在延迟的ssh连接上使用。

管理员设置除外,如果您有效地使用Vim的输入法与人体工程学键盘相结合,它将成为您预防腕管综合症的最佳防护工具。

看到vim的优势最好的方法是在家里开始一个轻松的项目,拔掉你的鼠标并用胶带覆盖你的箭头键。

并阅读帮助。

Two advantages of vi/vim:

  • it is very light-weight

  • it is installed on almost every *NIX system

I am maintaining a very big linux project on the remote computer. There is no choise to use Eclipse or similar GTK based IDE. I ve been working there for 3 years. And I set my vim just for this project. And still tweaking.

Now I can do any thing from the Vim: source control, sql, debug, compile, browsing - really fast browsing over 1Gb source code.

Visual Studio or Eclipse couldn t handle all of this. And If I had a choice I would n change Vim to other editor or IDE.

I learned Vim. It wasn t too much effort. Now I absolutely love ci" ci( cw V:s/from/to/g

I d say vim is definitely worth learning. I picked it up last summer, and it is now my editor of choice for just about everything (java is a stretch, but doable when I don t need extensive analysis support). As everyone has already affirmed, it is a wonderfully efficient tool.

For what it s worth, I only learned a fairly small subset of vim s features (which took a day or two) from a graphical tutorial, and a few odds and ends from here (long read), and the search and replace functionality, and I was hooked. I ve learned things since then, but at my leisure. I d say the learning curve flattens out at this point, but then, I was using it pretty heavily and was surrounded by others who were, too.

I m in the same situation as you, and as a beginner to Vim I originally found it a little daunting - the learning curve seems steep. From what I ve learned in just a few hours I m already feeling like I won t be able to live without it.

Here are a few links that I ve found for useful Vim screencasts to show you what it s capable of.

A good bit of advice that Bram Moolenaar (benevolent dictator of Vim) gave in that last link is that it would be inefficient to try to learn every single command and function, just figure out what it is that you re doing that isn t working very well, look for a way to make it more efficient and then make it a habit.

Yes, definately take the time to learn at least a bit of vi and vim . It travels very well.

You ll never be stuck when you are faced with a customer Unix/Linux/Mac system that you don t have install capabilities for. Even on Windows (if you do have install capabilities) Vim is free and easy to install. (As opposed to investing your learning curve purely in something like UltraEdit, which although an excellent editor might not be available for you all the time...).

Learning vi can set you up for learning other tools like sed , and regex in general: stuff that is generally transferable.

Plus if you want to be a proper geek, you just simply need to know vi/m or you ll look like a faker ;-)

I think it s definitely worth the time and effort to learn vim. To me, it makes typing and navigating around text so efficient, it s hard to imagine going back to emacs or ctrl/shift/alt/meta key combos.

Don t get intimidated by all the fancy features of vim. Once you ve used it enough, you ll figure out which commands you use the most, and you ll figure out which things you can forget about.

The amazing ubiquity of Vim, and the even more amazing ubiquity of Vi-clones in general, on Unix systems alone is enough to make it worth learning.

Besides that, the whole Vi-style thinking is something that I really think has made me a bit more productive. For a person not used to modes such as the command mode and insert mode, it seems a bit excessive to have to enter a mode just to insert text. But, when one has been using Vim for a few months, and has learned quite a few tips and tricks, Vim seems to be an asset that seems to be worth it.

Of course, the Emacs crowd says the same thing regarding Emacs-style thinking, but I gave up on learning Emacs because Vim was simpler and did the job for me.

I learned to like vi after watching someone who was very skilled with it navigate around to make edits at an insanely fast clip. You really can code quickly with it. Another reason I like it is that sometimes I find that mousing around in an IDE really hurts my hands after a while and vi provides a nice change. As others have mentioned it s also almost always available on unix systems and works well even over lousy connections.

One thing that I haven t seen mentioned is that knowing vi has the added benefit of "geek cred" in some circles. I can think of at least a few people who chuckle when they see a new programmer fire up nedit to make some changes to a file.

Don t be scared off by the number of commands, I ve not met anyone who used more than a couple dozen at most. I find it indispensable, because when I m thinking about code I m thinking about text, moving to thinking about mice just messes me up. The big tricks, I think, are to learn it a little at a time, and don t be hesitant to play around - the undo features is great for exploring its behaviors.

Also, if you get deeply into it, vim is scriptable. The possibilities are literally endless.

(Yes, all of this applies to emacs too...)

I was happy at my textpad and ecplise world until i had to start working with servers running under linux. Remote scripting and set up of config files was needed!

It was hard at the begining but now i can easily set up and tune up my servers.

You might want to learn vim because you might not be happy with the editors you re already using.

You might want to learn vim because many people say it is cool. Just look how many answers you ve got to this question.

I will provide an additional reason for learning vim. It has a reputation for the quality and the completeness of its docs. So you will find most answers to your questions in its help system as soon as you will manage to stick the proper keywords in your help queries.

To learn vi(m) fast one must first understand the whole design. Vim has a great set of cursor-movement commands, check a few (X is a character, # a digit):

j k enter arrows 0 $ w W b B ctrolD crtolU ctrolE ctrolY H M L fX FX tX TX , ; % gg G n N mX X

and many more it would be boring to enumerate. Many of these support a count before the command, like 4j to move 4 lines up.

Now, back to the design, you type a command like d for delete followed by a cursor movement and the command applies to the piece of text from the cursor position till the movement end. For example H moves to the top of the screen, dH deletes to the top of the screen and cH changes (replaces) to the top of the screen.

This design is quite powerful. It also reduces, or organizes, what you need to learn. Definitively the first step is to learn a few cursor movement commands. Say,8 or 10 at first. Then you are almost done.

Learning something new is always worth the effort, IMHO. I suggest you print out a cheat sheet and force yourself to use it day-in and day-out.

Vim is definitely worth learning to partly summarize what has been stated previously here are the main reasons:

  • Vi/Vim can be found on most unix systems.
  • Vim allows you to easily code without taking your hands off the keyboard.
  • If you plan you configure anything in a unix based system likelihood is you going to be editing a fair few config files, therefore you ll want to learn a terminal based editor, of which vim is one of the best (sorry emacs).
  • Vim compiles/has precompiled binaries for almost every OS out there. No need to post "I need a textmate alternative for [insert OS]", you ll have Vim instead!
  • There are a lot of good plugins out there to add alot of functionality, such as in-editor cvs diffs, although some of these require a fair amount of tinkering.

Also on a side note if you find you like the Vim key bindings, there are also IDEs which include vim bindings in their editors for simple commands, for example Komodo Edit.

For help on learning Vim, try typing vimtutor into your terminal and follow the instructions. There is also a book which is particularly good Hacking Vim

No. Learning vim is worth more than the effort.





相关问题
热门标签