I am looking for tips for learning Vim or Emacs the smart way

谁说胖子不能爱 提交于 2019-12-03 00:14:25

问题


I am a quite happy user of Eclipse (I mostly develop in PHP and Python), however I found the answers to "What specific productivity gains does Vim/Emacs provide over GUI text editors?" interesting enough to make me wish to try out Vim or Emacs as well and see if they would turn out to be a better solution for me.

I have the general feeling that Vim and Emacs are not the kind of editor you learn by "playing with it" though. I have the impression you must dedicate some time and effort to "study" them a bit, before you can benefit from their power.

So, I have two questions for the community:

  1. In the linked thread responders have essentially answered by commenting on Vim (often mentioning: "I'm sure Emacs has the same"). Google trends seems to indicate Vim is the mostly adopted between the two, however my first question is: knowing that I have no prior experience whatsoever on any of the two, and that I use and develop (mostly PHP and Python) on GNU/Linux systems (Ubuntu, Arch Linux), is there any of the two which would represent a better option to start with? (To be clear: my question is not about the quality of the editors but it is about what it is strategically better to learn in my situation).

  2. What advice would you give me on how to learn using it/them? I know this is a broad question, but it is deliberately so. Have a look at this answer (unrelated topic) for an idea of the kind of information / style of answer I am looking for [but do not feel obliged to answer that way... any contribution will be welcome, in any form!]

EDIT (on picking the "accepted answer")

I picked one answer as the accepted one just now, but I would like to say "thank you" to all those who shared their experience and advice: almost all of it has being useful to me in some way. The thread has definitively exceeded my expectations! Thank you! :)


回答1:


I would advise that checking out both is worth the time because of various reasons already covered by other answers or "Emacs vs vim vs XY" threads.

Still if you would have to pick one of them I'd go with vim because of one thing:

Availability

Vi(m) has the advantage that it is installed (not only available) by default on almost any *nix system. So no matter whether it is your system or someone else's or whether you are allowed to make changes to it or not, your favorite text editor and friend is there waiting for you.

Once you know vi(m) it feels awesome in those situations where you ssh into a machine and need to do something with text (navigating through a file, editing, whatever). You are going to feel like a King. I remember several times when I almost freaked out because nano or pico were not installed and I had to use "this ugly beast vi" which made unpredictable things when I started typing (because I wasn't in insert mode and didn't even know what that was) and when I was happy to have googled that ":wq!" gets me back out of hell. Now I can look back and smile about it.

I have the general feeling that vim and emacs are not the kind of editor you learn by "playing with it" though

Vim and Emacs are certainly editors that you "learn by doing".

Of course the question cries for including these highly scientific text editor learning curve graphs =)

Vim might be a bit harder in the beginning because its modal editing can feel quite unfamiliar at first. I think motivation is the key here. The article "Why, oh WHY, do those #?@! nutheads use vi?" explains the advantages quite well I think. In my opinion it really is worth to give it a try even while the learning curve might be steeper than with other editors and it sounds like you bring the necessary motivation.

Back to learning by doing.

Something I wish I would have done the first time:

Check out Vimtutor. It is an interactive tutorial which demonstrates the power of vim by showcasing it's basic commands and how they can be composed. Just type vimtutor in your terminal.

This helped me to really "get it" after trying to learn editing with vim several times in the past. The tutorial eases the learning curve dramatically as it explains the commands and makes you actually perform them so they become a habit. It really makes a difference compared to being frustrated because of feeling handicapped. Using vimtutor you also will see what the benefits of modal editing are and instead of fighting or ignoring it you are going to embrace it because you have experienced the advantages at first hand. I guess it would be pretty difficult to learn that all by oneself. So these 30 minutes are quite worth it.




回答2:


I have the general feeling that vim and emacs are not the kind of editor you learn by "playing with it" though.

My experience with emacs is actually quite the opposite. I tried going through the tutorial, but it didn't seem to help much. The way I ultimately ended up learning is with a reference card and just forced myself to use emacs on my code until I got it correct*. Then again, I do also have a screw loose. Your milage may vary. Offer void where prohibited. You get the idea.

One other piece of advice I recall reading somewhere is to try writing down a list of about 10 commands you want to learn and keep it by you while coding. Once you've mastered those commands, make another list of 10 more. Keep doing this until you've got a big enough chunk of the editor committed to memory.

*Note that the linked reference card is out-of-date. If you google, you can get a more up-to-date reference card.

knowing that I have no prior experience whatsoever on any of the two, and that I use and develop (mostly PHP and Python) on GNU/linux systems (ubuntu, archlinux), is there any of the two which would represent a better option to start with?

I'm an emacs guy, so my opinion should be obvious. That said, you're likely best trying out the one that more people you know seem to use. Having someone who's experienced with emacs (and I'd assume vim) is a great help.

If you don't know anyone who uses either one, choose whichever one you feel is the prettiest or has the coolest name. You won't know enough to know which one you'll like, so you might as well choose arbitrarily.




回答3:


For vim try vimtutor




回答4:


I came to Vim when I started using Linux after years of Windows development, and had to do a lot of work on remote systems via ssh. For the first couple of weeks hated it. After that I could not live without it.

Probably the best way to start is to use Vim in easy mode ([g]vim -y), most installations have a shortcut called evim. This runs vim in a mode that is in insert mode by default and remaps keys to the usual Windows ones (ctrl-S to save, ctrl-X to cut etc). You can then use it like a regular Windowsy editor but still access the power of Vim.

There is also Cream which is Vim + a bunch of scripts to make it behave even more like a Windows editor.

I started out using evim and Cream, but found I gradually transitioned to using 100% vim.

Also if you use gvim then most of the functionality is also available through the menus and you can see the keystrokes for the same functionality.

Also read the docs - there are extensive help files available on every aspect. I still browse them from time to time and find something new.




回答5:


Using VIM, I find the following quick reference card very helpful, especially for the stuff I don't do everyday: VIM QuickReference

For emacs, you should read the GNU Emacs Manual. Don't try to do everything all at once. Start with the basic stuff, and then move on to the more powerful features once you're comfortable with the easier stuff.




回答6:


Some time ago I decided to learn vim beside Eclipse as well because of its powerful textual editing, search and navigation features. But - at the same time - I liked the project handling, code completion, refactoring and debugging features of Eclipse and I did not want to lose them.

Nowadays I use an Eclipse plugin called vrapper which provides me nearly all basic features of vim inside Eclipse without losing any Eclipse functionality. Of course it is not a full-featured vim but it gave me the productivity gain I 'expected' (motions, the dot operator, registers and marks). Also, this plugin can be considered the 'trial' version of vim where you can learn all basic and some advanced stuff within your 'best-known' environment.

There is another interesting approach called eclim. Eclim integrates Eclipse with vim from the vim side so you can use many features from Eclipse within vim.

For learning the basics of vim, this graphical cheatsheet helped me a lot.




回答7:


I would go for Emacs. Explicit command name will makes your task easier. I switched to emacs after I had years of experience with vi and never looked back. Go with tutorial first. Hang out at #emacs in irc and people are happy to help you in real time, for whatever more you need.




回答8:


My advice for learning emacs is to understand that everything is done by a command (written in elisp) that is connected (bound) to the key strokes that you make. The power of emacs comes from being able to write new commands and use commands that are not bound to keys (there are too many commands to bind each one to a command.) as well, of course, read and modify commands that are already in emacs.

Next learn how to use the Help key and how to make a key binding list, then how to search for relevant commands (apropos) and see if they are bound already.

Be ready to take learning diversions into the emacs manual (Help, Read manual, Emacs manual).




回答9:


One argument in favor of Vim if you know Python is that you can write Vim scripts in Python. See :h python. Emacs requires you to learn elisp.

I find myself gravitating toward Vim for scripting languages like Ruby/Perl/Python/PHP, and for Emacs for languages that are more interactive (Lisp, essentially). If you develop your Python code using an interactive Python shell a lot, Emacs might be good, because you can embed a Python shell right into Emacs. If you write code and run it from commandline a lot, Vim can handle that easily enough via :make or :!.

I really recommend you learn both and pick whichever you like better. They are both worth knowing.




回答10:


Wow, vi/vim vs emacs, what a temptation...

From a vi-user's perspective...

  • Always There
    vi is on about every unix system ever released, in the default install, and available for Win
  • May save you from RSI
    vi uses home-row keys for just about everything, modifiers like control and meta are used only for rarely invoked functions and even shift-key use is moderate. This was probably all just a lucky accident, but don't laugh at RSI. It can happen to anyone, it's seriously painful, it's potentially career-ending, and it's hard to treat.
  • Starts up instantly.
    In the past, this was a huge advantage over emacs. Emacs users had to start up just once, and navigate everywhere within emacs. Today it starts faster, but in vi, it's perfectly reasonable to quit out of it entirely on every compile or test cycle.
  • Has an awesome line-mode
    The line mode in vi is backwards compatible to the original Unix ed(1) program, an editor that had only a line mode. That is, vi's regular-expression-substitution-engine-/-line-editor was once an editor all by itself.
  • Easily scriptable
    Got something you want to do to every .whatever file in your project? It's easy to write a declarative script that will edit a sequence of files. No need for imperative or procedural programming.
  • Easily extensible
    Vim, at least, can be extended in Python.



回答11:


First of all, be humble.

As long as you remain aware that they are very powerful tools you'll be ok. If you are finding a task very difficult, and you are thinking 'it's just me that sucks not the editor', you're in the right mind to learn and improve.

Bram's 7 habits are a good tenets to go by http://www.moolenaar.net/habits.html

Also I highly recommend having a go at writing a plugin. It doesn't matter what it does. It gives you the impetus to dive deep into the manuals.




回答12:


Maybe, a good way is to learn vim/emacs while using eclipse. Try vimplugin or emacsplus plugins for eclipse.




回答13:


This should really just be a comment, but against which answer ...

With Vim I'd suggest using the GUI version for a start, just dive in, the built-in help is excellent (:h and the screen splits adding a panel with comprehensive "hyperlinked" help pages). With vim the only potentially dangerous operation is a write, everything else you do is recoverable per command or edit (undo & redo).

The power acquired easily incentivises the learning.




回答14:


Here's the way you learn: Start typing. When you hit a point where you want to do something other than typing, look up how you do that. Repeat. It helps to start with a few basics, say 7 fundamental commands. Other than that, when you run into wanting to do some operation, look it up and use it.




回答15:


This great Tutorial was a big help for me for my first steps in Vim. It is a gently introduction and explain at the same time the philosophy of vim in a pleasant way:

aByteOfVim




回答16:


The way I learned emacs was mostly by doing both of the following:

  1. All the GUI menus show you the key-bindings you can use to execute the same command as that menu item. Pay attention to the bindings for the menu items you select a lot, and try them out manually next time you get a chance.
  2. ctrl-h ctrl-h (think "Help! Help!") brings up a buffer that shows the various types of help available. If you then hit the "b" key (the buffer calls it "describe-bindings"), you will get a list of all the key bindings that are available in the buffer you are working on. Just peruse that every now and then with an eye for commands that look useful. Try them out when you get a chance.

As for vi, I learned it in the days before vim, so I pretty much had to use man vi to figure it out. Most of us emacs users will tell you that all the vi you need to know is :q! ("quit, and I really mean it"). :-)

But in truth if you are a Unix user you need to learn at least enough vi to do simple edits to config files and save them. You never know exactly what (if anything) you will get when you try to start emacs on a strange system Unix system, but vi is always there.




回答17:


Nearly everything you see or interact with in Emacs can tell you about itself -- you just need to know how to ask it.

To learn Emacs, learn about the current Emacs context: what the values of things are, what the relations between them are, how they are denoted, how you can change them or otherwise interact with them.

The most important thing to learn is that Emacs is Emacs Lisp -- it is a Lisp ecosystem. Learning Emacs means also learning Emacs Lisp -- the more you know, the better. Lisp is the most flexible and most powerful way in which Emacs realizes itself as "the self-documenting, extensible editor".

Icicles can help you learn Emacs and Emacs Lisp. It helps you ask Emacs about itself. This page gives an overview of the ways it does that: Emacs Newbie with Icicles.




回答18:


Don't get caught up in the vi(m) versus emacs religious war. They are both great editors. I originally started with VI (real VI not VIM) and later started using Emacs. These days, I tend to use both, but emacs more because emacs has some features I need which are not in vim.

The real challenge and what you should be aiming for is how to be as efficient, quick and accurate as possible with your editor of choice. Both VI and Emacs have a lot to offer in this respect. However, much of it boils down to two main habits you need to develop

  1. Don't use the mouse. Both editors were created when mice were not the plague they are now. When it comes to editing, cutting, pasting, highlighting etc, both editors offer keyboard equivalents. Use them and keep your fingers on the keyboard. You will be surprised how much faster you will become

  2. Avoid the arrow keys. This is for a similar reason. The arrow keys tend to make you move your hands off the main keyboard. In the end, this also slows you down and makes you less efficient. Both editors provide far more convenient functions which are faster.

These are the two main things to focus on when learning either of these editors. There is lots more, but to start with, just start with focusing on using the main keyboard.

After you have got that down pat, then begin to think about how you can tweak your environment to suit your needs. By this time, you will be familiar with the power of the editor you have chosen and will probably have some ideas. Both of these editors are very configurable. I find emacs is the most configurable, but you can easily get lost iin writing elisp to configure things and before you know it, your an elisp programmer who does a bit of PHP and Python. To some extent, the same can happen with VIM, but to a lesser degree. However, note that the defaults have usually been set by people with lots of experience and who probably know something you don't. Avoid making the mistake of trying to modify either editor to be what your use to. Learn how it works with minimal config first and then change once you have an idea of why it was done some way - know the rules before breaking them.

If your serious about programming, your editor will be your most important tool. Other important tools are your screen, your chair and your keyboard. The rest is incidental.



来源:https://stackoverflow.com/questions/1812926/i-am-looking-for-tips-for-learning-vim-or-emacs-the-smart-way

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!