5 ms·
Top ten essential Emacs tips
- Paperflyer 18y agoHere is an interesting thing: Search google.com/trends for Emacs and Vim: It suggests that in the last few years, both editors have lost users, but Emacs lost them faster than Vim. While Emacs started out with twice the popularity of Vim, Vim is now stronger. Personally, I tried them both for some weeks each, but in the end settled with TextMate and WriteRoom, as both Emacs and Vim somehow felt too clunky for me.
- sophist 18y ago1) Use vim instead.
- julianb 18y agoRegular expression search and replace is also killer.
- ajross 18y agoYes. Although if you're still learning regexes, I'd suggest staying away from the emacs implementation. It's different from perl's (or pcre, which is the library that everything not perl actually uses) syntax, which is the one you really want to know. There are a bunch of annoying incompatibilities.
- msg 18y agoI've found I don't miss much from Perl 5. The only things I've found really funny are backslashing special operators that you don't in Perl, like \( \| and \{. Oh, and \s- for whitespace is very weird to me. And there's no \d. And instead of $1 in the replacement, you do \1. Once I got used to it, I found them very close to each other, at least for everything I do. Like Steve Yegge (in Effective Emacs), I alias query-replace-regexp and use it every day. Lots of other good tips and pointers to interesting topics there. http://steve.yegge.googlepages.com/effective-emacs http://steve.yegge.googlepages.com/effective-emacs
- silentbicycle 18y agoM-x re-builder can help you learn them interactively, though.
- davidw 18y agoWow, that's a cool one... I love that about emacs: even after years of using it, I'm still learning lots of cool things.
- silentbicycle 18y agoTwo more quick tips: 1. The "kill ring" (what other interface cultures might call a clipboard) is a circular stack, not just one slot. If you try to paste ("yank") and discover you cut/copied over what you meant to paste, you can hit alt-Y (or M-x yank-pop) to replace it with successively earlier things. When you reach the end, it loops back to the newest. I think it has a stupid name, but it's really useful. 2. Learn the terminology. Emacs came of of a very different user interface culture, and sometimes feels like it came from a parallel universe. The documentation (info pages, apropos, etc.) become much easier to search when you know what various parts of the interface are actually called. I don't know of any "Emacs to vernacular Windows/Mac/Linux interface cliche" glossary, but reading through the documentation, even what should be the really basic parts (e.g. "how to open a file", the tutorial) will help you acclimate. ("find-file", buffer, mark, "major mode", etc.) It helps that the Emacs manual is available on the web -- that way, people don't need to figure out how to navigate info pages first. :)
- jrockway 18y agoI think it has a stupid name, but it's really useful. 2. Learn the terminology. You wouldn't think the name was stupid if you followed your second piece of advice. A ring is a data structure that's like a queue, but after it fills up, the old elements go away. The kill ring is called such because it's a ring that stores killed text.
- silentbicycle 18y agoThe kill/yank names rub me the wrong way because where "cut and paste" suggest X-acto knives and glue sticks to me, that is, editing text on paper, there's no metaphoric grouping between "kill" and "yank". It also makes expressing the act of copying awkward. Copying is called "kill-ring-save", which is a kind of terse "kill-it-but-don't-actually-kill- it-just-copy-it-as-if-you-did". It further breaks down any metaphoric concept tying them together. I'm not arguing that "copy/cut/paste" are better terms because they're already used by most people, but rather because they collectively express the operations in terms of an existing, analogous, and likely familiar idea. (I think the "ring" part of it is perfect, though.)
- fallintothis 18y agoNot to troll -- indeed, I am attempting to be constructive -- but in case anyone was interested in (what I know of) vim's equivalent functionality, here's what I have so far: 1) Several options: :help <something> :h <something> Shift-K to run a program to lookup the keyword currently under the cursor (the program defaults to man). On that note, you could just :! man <whatever> if so compelled. 2) qq = record macro to register q. @q = replay macro at register q. 100@q = repeat macro q 100 times. @@ = repeat the previous @<whatever>. The author notes that you can tell Emacs to "please repeat this macro until it would cause Emacs to start beeping", which I found interesting. I'm not sure if there's a specific way to do this in vim; I often just go with, e.g., 1000@q (or whatever arbitrarily large number you want. You can check how many lines are in a file, among other statistics, with g<ctrl-g>). So long as the macro ended with a j (or whatever motion you wanted, technically) it would continue carrying down the lines. It seems as though you could be able to execute macros on some chunk of text, perhaps with visual line select. Hm... Another interesting feature the author notes is "counters let you insert a different number every time a macro is run." I've had some annoying experiences bending over backwards for this, so I'd like to know an easier way, but it's certainly possible using the C-A and C-X keys, which increment and decrement a number under the cursor, respectively. 3) Ctrl-v for visual block mode (remapped to Ctrl-q for :behave mswin, since Windows captures this as Paste); then, simply move around with the regular keys and perform fancy editing to your heart's content. I use this often, for instance, to insert comment marks in a chunk of text. Go to the first column & line of the block, ctrl-v, hold down j till the region reaches the last line you'd like, then shift-I, type your comment characters (e.g., "//" or ";" or "#"), then <esc> and the insert takes effect on all lines of the previous region. Also useful during the many adventures in the different visual-select modes, use gv to re-select the previous visual area, should it happen to become deselected. For instance, when I am holding down j in the previous example and prematurely hit Shift before letting go of j, it joins the lines up. Argh! u (undo) then gv to continue on my way. 4) When I first read about this, I was immediately interested. For similar functionality (couldn't claim whether or not it was the SAME, strictly, as I don't actually use Emacs), there's the extension that I now adore: YankRing. http://www.vim.org/scripts/script.php?script_id=1234 http://www.vim.org/scripts/script.php?script_id=1234 5) I tend to use :diffsplit, though there are other ways to work with this. As per item 1, :help diff. 6) Sad to say I'm at a loss here -- not to say vim couldn't do this, but rather I've never needed to do this in my range of experiences (clearly limited compared to that of the author's). If anyone could fill this in, I'd be interested. 7) The few times I work with a language that doesn't have a shell: :make Though there are parameters and options to tweak with. For instance, which program to use by default, whether or not to create a temp file for the errors, jumping to the first line containing an error, etc. As stated, I do most of my work in languages with shells anyways, so I'm not an expert with this command. :help make, for more info. 8) Admittedly not built-in (being against vim's Do One Thing Right philosophy, I suppose), but the plugin I use for this is vcscommand: http://www.vim.org/scripts/script.php?script_id=90 http://www.vim.org/scripts/script.php?script_id=90 with a Mercurial backend, since the base plugin is for CVS, SVN, SVK and git: http://www.vim.org/scripts/script.php?script_id=1898 http://www.vim.org/scripts/script.php?script_id=1898 Then, it's a matter of :VCSVimDiff, :VCSCommit, :VCSAdd, which you can remap to whatever keystrokes you like by editing your .vimrc (see item 10). 9) Again, I've never done such things, so if anyone could step in for our fellow vimmers, that'd be great. 10) You can edit your .vimrc to remap keys as you'd like -- including binding them differently per mode you're in. Taking some silly examples from my .vimrc: "Maps ctrl-enter in insert mode to open a line below your current line: imap <C-CR> <esc>o "Maps ctrl-enter in normal mode to simply o, in case my muscle memory goofs and "doesn't notice I'm in normal mode: nmap <C-CR> o You can also set abbreviations, which will expand as you type: "Fix typo abbr teh the "automatically expand {{ into a curly-brace block, the idea being to hit Enter "after typing the {{ ab {{ {<cr>}<esc>kA
- jrockway 18y agoUh yeah, this: (global-set-key "\C-cs" 'shell) is deprecated now. You need to say: (global-set-key (kbd "C-c s") 'shell)