Hacker News new | past | comments | ask | show | jobs | submit login


I really want to learn either Vim or Emacs but I've never been able to decide which one to learn. Every time I've tried to search about this topic I end up in petty wars. Help?

Even though I'm more of an Emacs user, I'd say if you're going to learn one, learn vi. Not vim, mind you: nvi, the original one (you can emulate it in vim with "set compatible"). Use it for a few months until you get muscle memory for it. Just about any UNIX-like system you'll work on, anywhere, has at least the old vi, and it's very useful to just have that muscle memory tucked away.

What's more, if you prefer the Emacs environment, you can run a vi-like editor in it (Evil). Emacs keybindings, on the other hand, are the default keybindings for GNU readline, which is used in a lot of shells and related programs. Additionally, I know that OS X allows you to use Emacs keybindings in any text field. (I am not a mac user, can't comment on this.)

(Disclaimer: I am a happy Spacemacs user, and it would take a lot to pry it away from me.)

I'd recommend learning vi, so you can learn how awesome modal editing is. Then, learn Emacs' basic commands for line editing (so as to make readline apps easier to work with). Once you've done that, evaluate whether a (Neo)vim with plugins or Spacemacs setup is better for you, then choose one of those.

As an avid vim user who has tried Evil mode, emacs, and even spacemacs, I fully agree with all of the reasons you listed. To add to it:

- *-mode (specific syntax highlighting, commands, etc. based on project or task)

- edit/save remote files via built-in TRAMP [0]

- built-in plugin manager (interactive, or via emacs init config)

- MELPA [1]

- Non-blocking (e.g., run tests in one buffer while editing source in another)

- client-server approach (neovim adopted this, but emacs has had far more time to work out the kinks)

The main reasons I stay with vim are:

- already committed to vi-like muscle memory (and evil-mode, while admirable, doesn't cut it)

- no translation of VimL configs and plugins to Emacs Lisp

- many plugins for languages, frameworks, etc. which I use daily are severely out of date in emacs (and I'm too lazy to maintain them myself)

[0]: http://askubuntu.com/questions/79100/how-to-open-a-remote-fi...

[1]: http://melpa.org/

I prefer the Emacs environment: I love TRAMP, org-mode, and the simplicity of getting a fully-featured IDE just by adding a list to my spacemacs configuration.

Do you use neovim?

As a vim user, I have to disagree with the "Not vim" part. Learning only vi would lose too many of the advantages of vim.

Use vim, learn vim all the way. If/when you're working on an "old" vi (e.g. the one in busybox, for embedded developers), you'll need to drop some of the more advanced stuff, but you'll still be able to do what you want, edit some config file or such, though it may feel a bit awkward at times. But when you're doing the heavy editing, you really want to use all of vim.

Disagree. I'm talking about building basic editor muscle memory and knowing the base set of ex commands that you can use literally anywhere. For that matter I'd say what's really important is that you learn ex.

Vi is vim without text objects ie pretty poor (and one of the most important things a vim user should know).

Your advice is very misleading in 2016.

I don't think there is an active vi codebase, vi is actually vim in compatibility mode in most operating systems.

nvi is actively maintained by the BSDs, which all ship it as the default system editor. Apple did too until IIRC two versions ago.

That's actually a very good point. Thanks!

I'd advise you to learn vim, for a couple of reasons.

The main one is the concept of composability [0] - in vim, you're speaking a mini-language. You have commands (delete, copy, make uppercase,...), and a number of movements (right, down, to the next occurrence of a word, to line 27,...) or objects (word, line, paragraph, html tag, text within quotes, ...) to work on. These can be combined in any way you like, any command can be applied to any movement or object. So if you have a plugin like vim-angry that adds a "C-style function parameter" text object, all the commands you know can be applied to that. In contrast, in emacs, you have a number of commands (kill-line, kill-word, ...), and that's it. You have to get by with those. If they didn't implement the command you'd like to use, tough luck.

A second (minor) reason for me is that I work in the embedded software world, and usually on an embedded linux, there's at least some variant of vim or vi available, while emacs is very rare.

Take my advice with a grain of salt : I've never really used emacs, so I can't compare from first hand. From what I've heard, emacs is also a very good editor. To me, the question "should I use vim or emacs" is more or less the same as "should I use firefox or chrome" - I'm a chrome guy myself, but I don't consider firefox to be crap, nor its users to be idiots. Internet explorer on the other hand,...

So my advice : learn vim. And if you don't, learn emacs. Just learn to use either one properly, and you'll be way faster at editing than people who don't use those.

[0] a.o. https://medium.com/@mkozlows/why-atom-cant-replace-vim-43385...

I'm not sure I'm convinced by the composability argument. Isn't composable the default for text editors? Emacs (and most text editors) let you select a portion of text (Emacs calls this marking a region) and then decide what to do with it: delete it, cut it (Emacs calls this killing), convert to upper case, etc. Vim mostly uses the other order: Commands first, motion or text object later (except in visual mode where it's like other editors: Select something first, command later).

So you just need to implement a bunch of selection commands to get Vim-style composability. I think lots of these modern text editors like sublime or atom come with select word, select parenthesized expression, select paragraph, etc. If the editor is extensible you can define new selection commands and compose them with the existing commands that operate on a region, just like Vim. Emacs certainly has a bunch of marking commands.

The extra commands you mentioned in Emacs (kill-word, kill-line, etc.) are just for convenience: Shortcuts for common cases. In Vim you can delete to the end of the word with dw. In Emacs you could also do a 2 keystroke solution: do mark-word, delete-region (you could use backspace, Control D or delete for that second second thing since they "operate on the region of the selection is active", so C-@ <backspace> would do it). Unlike Vim you also have the option of a single chord with the convenience command kill-word.

Can you point me to some documentation from atom or sublime, where they explain which kinds of selections you can make? I wasn't aware that certain editors seem to have many modes of selection, and a quick web search doesn't reveal very much. I'd like to be able to make a comparison with vim's text objects and movements. My gut feeling tells me that vim will still have more "targets" for a command, and more accurate ones, but I'm biased.

But the "select text and then apply command", as I understand it, still has a major drawback compared to vim's way of working : the dot-command. In vim, you go "daa" (delete an argument - i.e. delete the argument, including the comma which separates it, if you have the vim-angry plugin). Then you move to another argument, you just press dot, and the same thing happens.

Also, does the selection thing accept counts?

I should stop talking about editors I don't use. Let me focus on Emacs with some comments about Textadept (I've never used Atom and only tried Sublime Text for a day).

1. Yes, the ability to repeat with dot is advantage of the Vim model. Emacs just repeats the command part not the marking part too, not as useful as dot in Vim!

2. In Emacs every command accepts counts, just like Vim. Textadept doesn't offer counts, I believe. I think counts are probably an advantage of Vim and Emacs over most(?) other editors.

3. About Vim having more motions & text objects: Probably, but Emacs is close. Without extra packages you have: words, symbols and S-expressions (the names come from Lisp but these do something sensible in most languages: Symbol is usually identifier and S-expression is something like delimited expression: A string, a parenthesized expression, a block in curly braces or brackets, etc.), lines, sentences, and paragraphs. Texts packages add other targets like LaTeX environment. One thing definitely lacking in Emacs is that Vim usually offers two variants that differ slightly at the ends (like w vs e, or i( vs a(), those minor variations are pretty useful.

My point is just the saying other editors don't have the ability to combine commands with different things to operate on is obviously false, and claiming is unlikely to convert anytime to Vim. Instead Vim bloggers should focus on how Vim makes the basic composability idea even better with things like counts, repeatability of composed commands, and richer set of selection commands.

Regarding 1. Emacs does have keyboard macros. A bit more involved than just hitting dot, but they do let you compose an arbitrary sequence of operations (including selection) that can be repeated or saved and applied later.

it's the "a bit more involved" that makes it very weak in comparison. The power of the dot command is exactly that it takes one single keystroke to repeat the last action. You don't have to think in advance "I may want to repeat this action, let's add some keystrokes to store this in a macro." You don't have to push a few keys to repeat the action, just one single key.

This is the best article I've seen that describes the huge advantage of composability:

Why Atom can't replace Vim: https://medium.com/@mkozlows/why-atom-cant-replace-vim-43385...

I think I understand the advantage of composability. What I was saying is that it is not unique to Vim. Vim uses "command; motion-or-textobject" in normal mode where most editors use "select-what-you-want; command" (which is what Vim does in visual mode). If your editor has a good stock of selection commands (some have select word, line, paragraph, parenthesized expression, etc. -- I don't use atom but Emacs and Textadept have all those and more, like select LaTeX environment) and a good stock of commands that operate on the selection (like delete, cut, wrap in parenthesis, uppercase, etc.), I'd say you have composable editing.

I don't think the link you have addresses my point at all.

It seems pretty clear to me that it does indeed address your point.

That you can build up sophisticated actions just by knowing the primitives and text objects is the point, right? And not having to memorize different commands and different selections.

From the article:

But now let’s look at delete commands. Let’s say you want to delete a word, delete to the end of the line, delete to the end of the file, or delete to the end of a paragraph. Emacs only has two of these functions: kill-word and kill-line. Atom has the same two, more or less: deleteToEndOfWord() and deleteLine().

Vim, though, is different. Vim only has one command: d, which is “delete.” What does it delete? You name it, literally. The d command gets combined together with those commands for movement: dw deletes to the next word, d$ to the end of the line, dG to the end of the file, and d} to the end of the paragraph.

This is where Vim’s composability leads to its power. Emacs and Atom don’t have commands for deleting to the end of a file or a paragraph — even when they have commands to move to those places. But in Vim, if you can move to a location, you can delete to that location.

And composability is about more than just power, it’s also about learnability and consistency. The command for copying text in Vim is y. Do you know how to copy to the end of the line/file/paragraph? Of course you do: It’s y$, yG, and y} respectively. The command for increasing the indent is >, so you instantly know >$, >G, and >}. Convert to lowercase is gu, so… sure enough: gu$, guG, gu}.

Well, maybe the author of that post just hasn't noticed the similarity between:

Vim normal mode grammar: command motion-or-textobject

Other editor's grammar: select-a-region command

(Also, Vim visual mode grammar: select-a-region command)

Emacs has lots of command that can select a region. They tend to be called mark-something. There are commands for selecting words, sentences, paragraphs, function definitions, S-expressions (the name comes from Lisp but they're defined to be something useful in every language, usually something like "any delimited construct in the language --strings, blocks, array literals, etc."). Once you select something you can apply many actions to it: you can delete it, uppercase it, rot13 it, sort the lines in it, wrap it in parenthesis, etc.

Maybe what tripped the author up is that additionally Emacs has other commands like kill-word, kill-line that are shortcuts for common combinations of a motion and a command. The author is correct in saying that these convenience commands are not composable, but they're nice shortcuts to have (and by the way, contrary to what the author says Emacs does have a kill-paragraph command).

So you to delete a word you can do:

Vim: dw

Emacs composable style: M-@ C-D (that is, mark-word delete- region[^1])

Emacs shortcut: M-D (kill-word)

Atom composable style: Option-Shift-f backspace

Atom shortcut: Option-d

(I got the Atom ones by Googling, I don't if they are right, but if they're not, I'm pretty sure correct ones exist: Atom has both a composable way and a shortcut.)

Vim propaganda should stop saying other editors lack composable commands. Even notepad.exe lets me use any of its paltry motion commands[^2] available to select something and then use a generic delete command to delete whatever I selected. "Composability" is the default mode of operation of most text editors.

Vim propaganda should focus instead on the very real advantages than Vim's command model has. For example:

- dot repeats the whole command/motion pair. This is fabulous!

- Vim has counts so you can delete 9 words just as easily as 3 words. (Emacs also has them, but lots of editors don't, and they're superhandy.)

- Vim has lots of little variations of the motions and textobjects so you can pick exactly what you need, other editors tend to have fewer. For example, for words, Vim has w, e, aw, iw (and probably others I'm forgetting) which are related but a little bit different.

(Also, personally I think Vim bloggers should recognize that those non-composable commands like kill-word are nice optional shortcuts, that are actually a tiny advantage other editors have over Vim. Try playing VimGolf in Emacs --using the nice vimgolf Emacs package, because of course Emacs has a package for that-- and you'll see what I mean.)


[^1] OK, techinically C-D is delete-forward-char in the default keybindings, but when a region is active it acts as delete-region.

[^2] It's limited to character, word and line, I think. But people forget even the lowly notepad.exe has word motions (all text widgets on Windows do).

It's an interesting point you make, that other editors also turn out to have some form of composability. However, the fact that this is the first time I've heard somebody talking about this might have some underlying meaning. Maybe vim is the only editor where people actually use the composability, because it's only in vim that it's actually usable :-)

In vim, the most common way to delete a word is also the composable way, and also the shortest (just two keys). In emacs, most people probably learn the shortcuts first, so they don't have the muscle memory for the composable style. The composable style is also two modifier keys longer. So in emacs, first you learn it the "regular" way, with all the shortcuts, and then when you want to learn composability, you have to relearn all sorts of basic things, and spend more keystrokes, to have that. In vim, you've learned some basic commands (dw, c$, yia, ...), and then I tell you about composability, and you understand how you can combine all those commands and movements you already know :-)

I agree with everything you said. It's certainly true that Vim (well, I guess this comes from vi) takes composability much more seriously than other editors.

I wish Emacs in particular took composability a little more seriously. Probably combining selecting an acting into a single repeatable command by default would be too un-Emacsy (after all, macros are very lightweight and there is evil mode), but it would be great to have all the fine-grained selection commands that Vim has. For example, AucTeX has a command to mark a LaTeX environment, but it also should have what Vim would call "inner LaTeX environment". As a more basic example, I wrote my own mark-line command because what I want to do with lines isn't always kill them! With builtins I think the best way to mark 5 whole lines starting from the one you're one is C-a C-SPC C-5 C-n, which is awful. With a mark-line command you just do M-5 M-L (depending of course on what you bind it too).

There have been attempts to bring better composability to Emacs besides Vi(m) emulators, in particular in a non-modal way. But the ones I've tried haven't fully convinced me. It's definitely possible to do it, but doing it properly might be a major undertaking. Maybe I should just start using evil again.

I was sort of in your situation a while ago and wanted to learn vim, but was a bit put off by all the legacy that it carries (also spoiled by sublime's multiple cursors).

I then discovered kakoune[1] and liked its design. I started getting familiar with it and using it more and more, and I think its core is much more solid than vim/emacs. It definitely doesn't have the same community support and plugins but it's already quite feature rich.

[1] https://github.com/mawww/kakoune

Just use whichever your social group uses, as they'll likely be helping answer any questions about it.

Then, if your friends use emacs, use evil-mode because vim is the best.

They're both great, but have different philosophies. Just try one and see if you like it. If you really don't get on with it, try the other one.

It'll probably be easier to go from Vim to Emacs (since Emacs has a really good Vim emulation plugin) than the other way around.

Vim is a useful skill to have because sometimes you need to configure a server. However, I'd encourage you to really learn a modern editor like Sublime before emacs, then visit emacs long enough to figure out if you want it.

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact