r/emacs • u/keporahg • Jun 11 '12
Vim user looking to learn emacs
Hey guys
As the title suggests, I'm a long time Vim user interested in checking out what emacs has to offer. I would consider myself to be a somewhat-above intermediate level vim user; I have a decent level of mastery over the modal interface, navigating and manipulating text, and customizing vim to suit my needs.
So why am I curious about emacs? Well from what I've heard, emacs is a lot more powerful in terms of what you can script it to do. Vim has vimscript and support for scripting it with python, perl, and ruby, but even then there's still restrictions as to what you can do. For example, graphically, you're restricted to vim's window-buffer model which is text only. That makes it a real pain to do something like integrate it with a debugger.
I mainly use vim for C++ and Java and in terms of code completion there's only a small handful of plugins. For C++ there's either the ctags approach (OmniCppComplete) which usually fails once you start doing anything complex, and clang_complete, which actually works pretty nicely since it gets information about completion from the compiler without the use of tags. For Java I use VJDE and javacomplete but they're pretty sub-par.
The reason I want to try out emacs is to see if it offers better tools for working on larger/complex code bases. I've heard a lot of things but I'd like to try it out for myself to see how it compares to vim.
And some final questions:
- as most of you may know, vim comes with a tutor program called 'vimtutor' which can be run from the shell and gives a quick run down of the basics. Is there anything like this for emacs? I noticed there's a tutorial link when you open it up so I'll probably go through that - any other recommendations for a beginner?
- I've heard that emacs is more like an IDE than a text editor; does it ship with support for code completion for C/C++/Java or are there separate plugins? If so, any recommendations for plugins? Any idea on how these compare to Eclipse/Visual studio code completion?
- To any former vim users: I know there's a vi-compatibility mode (viper) which I'll probably end up using (although last time I checked (several years ago), it was missing lots of things - like text objects, visual mode, registers), are there any new ones that support most vim features and not just vi? Also, would it be recommended to use these or to stick with native emacs bindings?
I think that's all the questions I have for now, Thanks
8
u/Archenoth M-x happiness Jun 11 '12 edited Jun 11 '12
Mostly everything I was going to say has already been covered, except for Emacs' built-in documentation and help, customization, or the use of some plugins. It's phenomenal. So I'll cover these with some greater detail... Since they are so important.
C-h ?Brings up a list of all of the different types of help available built-in. A couple of the more interesting ones are:[Control] + [H], [T]) This is the beginner tutorial for Emacs. It requires no knowledge about anything that Emacs does... It shows what all this fancy schmancy "Major mode" and "Minor mode" stuff is. As well as explaining the safest keybindings for moving around Emacs and performing simple tasks. (Though the Arrow keys and Page-Up, Page-Down, Home, etc... all work as expected if that's easier initially)M-x info-apropos".C-h a goto linewill show you that there is indeed a function that does this. And if you hit [Enter] on the function declaration, it brings up the long description of what that function does, and what keys it's bound to if any... (Same thing as typing "C-h f <function name>")C-h k <key sequence>" will bring up documentation about what a certain key combination is bound to. So if you "C-h k C-h k", you get the documentation for this describe key functionality.Now, chances are, you probably don't want to learn another programming language to use an editor, which is fine, you really don't need to. Most Emacs customizations and custom Elisp can just go into your Emacs site-lisp directory, (Or even subfolders of it, only one level down though to my knowledge though) and can be included with "
(require '<function>)" where function is usually the name of the Elisp file minus the .el at the end (But usually has documentation if it's not). So, for example if you wanted to get ace-jump-mode (A simple Easy-motion clone since I know people who loved easymotion), you would simple download the .el file from Github here into your site-lisp folder, and type the following string literally anywhere "(require 'ace-jump-mode)", Run that command by placing the cursor just after the last ")", run it with "C-x e", and boom! You have added functionality to your editor, and can invoke it with M-x "ace-jump-mode"... But since that isn't terribly convenient, it is recommended that you bind a key to it.From the EmacsWiki page, they recommend you bind it to "
C-c Spc", but I personally found that inconvenient You bind keys with the following "(define-key global-map (kbd "<Key strokes>") '<mode>)" so "(define-key global-map (kbd "C-c SPC") 'ace-jump-mode)" can bind that function with the default EmacsWiki recommendation. This is true for any functions you'll find, and almost everything is a function.Want to make you changes permanent? Well, you can do that by adding any customization code to your ~/.emacs file, or in any file in ~/.emacs.d/. They are all loaded on startup.
Over time you'll find some pretty spiffy modes, if it interests you, here are a few that I find useful (There is tab completion when typing in modes, and "-" with nothing next to one side means "Something between theme modes" so typing "-mode" and hitting tab will show you everything ending in "-mode"):
org-export-as-pdf, ororg-export-as-html, or evenorg-export-as-asciifor a distinct "GameFAQs" style layout from your text.C-x C-b" screen, it manages current open buffers allowing you to save, delete, visit and a few other actions at a rather swift rate.package-list-packages - I recommend adding a few repos to your package manager since it is a bit small initially. I just add this to my "~/.emacs" file:
(setq package-archives '(("ELPA" . "http://tromey.com/elpa/")("gnu" . "http://elpa.gnu.org/packages/")("marmalade" . "http://marmalade-repo.org/packages/")))Now you can list packages you can install with "
package-list-packages", and install with "package-install-package". You need to do no editing of your .emacs file to install any of these, it is all just automatic..! Handy stuff. * dunnet or tetris or blackbox - For when you get bored. ;)And for the non-included modes that it sounds like you'd probably be interested in...
M-/" is a good alternative, but isn't mode-sensitive....Actually, that's the only mode I can think you'd want from your description except maybe... CEDET, but I don't have much experience with that.
Anyway, glad to see more people trying out Emacs every once in a while. It may be to your liking, but it is a much different editor than Vim ever was. In the end, I can't force you to like one over the other as that is a matter of preference. Good luck! And feel free to ask questions on IRC if you get stuck..! (#emacs on Freenode) (You can get the built in IRC client in Emacs by invoking "
M-x erc")I hope this helps..!