5 ms·
Adding further to my previous comment: What if we really need to do regex, say replace "f.." with "bar"? The input sequences then look like this: On Vim: <Shif
by susam 6y ago
Adding further to my previous comment: What if we really need to do regex, say replace "f.." with "bar"? The input sequences then look like this:
On Vim: <Shift>+; (:) <Shift>+5 (%) s/f../bar/g <Enter> (16 key strokes)
On Emacs: <Alt>+<Shift>+, (M-<) Ctrl+Alt+Shift+5 (C-M-%) f.. <Enter> bar <Enter> <Shift>+1 (!) (17 key strokes)
Although, the number of key strokes are close to each other for both Vim and Emacs, I am pretty sure most beginners would feel there is a slightly increased cognitive overhead involved in Emacs when compared to Vim. The Vim input sequence is just : to invoke the command line mode, followed by an ed-style substitute command. However, the Emacs input sequence is M-< (beginning-of-buffer), C-M-% (query-replace-regexp), pattern, replacement-string and ! (to prevent further prompts). For an experienced Emacs user, all of this becomes muscle memory and becomes as efficient, if not more, as the Vim equivalent pretty soon.
Also, there is evil-mode in Evil for those who really want the Vim-editing experience along with the power of extensibility that Emacs offers.
- melling 6y agoWhen you spend hours in your editor, day after day, you aren’t a beginner for long
- lars512 6y agoThat’s unfortunately not my experience from observing other engineers. Many get stuck at a “good enough” level with their tools and never seem to learn the shortcuts which would allow them to code and edit faster.
- mvolfik 6y agoYes, that's exactly my experience with Emacs - I read their tutorial to do basic tasks (open files, open windows, switch windows, basic replace). Also, I never learned to use their "smart" (?) terminal, python console... Otoh, then I tried Pycharm community, and eventually redeemed my github student pack for free pro version, and now I can't imagine living without it. Also there's a great plugin that annoys you with small non-modal popup in LB corner whenever you use mouse and reminds you of the correct hotkey
- teddyh 6y ago> Alt+Shift+5 (M-%) You meant “Control+Alt+Shift+5 (C-M-%)”.
- steerablesafe 6y ago> Ctrl+Alt+Shift+5 My fingers just broke reading that. Having said that I don't have a right alt key, as it's altgr . I suppose it's advisable to have two alt keys to use emacs.
- hinkley 6y agoI think people mash all 3 control keys with the left hand and reach across for the 5, or stretch their fingers very awkwardly and do all four. We’re into Rachmaninov territory at that point.
- susam 6y agoOne can also invoke the query-regex-replacep functionality by its name instead of the key sequence C-M-%. For example: M-x q-r-r Tab Enter. The Tab key autocompletes the partially entered name q-r-r to query-regex-replace. This is going to be a lot more convenient for those who want to avoid the four finger chord.
- deleted 6y ago[deleted]
- hinkley 6y ago> On Emacs: <Alt>+<Shift>+, (M-<) Ctrl+Alt+Shift+5 (C-M-%) f.. <Enter> bar <Enter> <Shift>+1 (!) (17 key strokes) I get 19 here, and a lot more keys off the home row. Four keys at once is quite a bit slower for many people than two or even three.
- susam 6y ago> I get 19 here, Here is the key stroke count I get expressed in a step-by-step manner: ;; Type M-< (Alt+<) to invoke beginning-of-buffer: 1. Alt 2. Shift 3. , ;; Type C-M-% (Ctrl+Alt+%) to invoke query-replace-regexp: 4. Ctrl 5. Alt 6. Shift 7. 5 ;; Enter the regexp pattern "f.." at the prompt: 8. f 9. . 10. . 11. Enter ;; Enter the to-string "bar" at the prompt: 12. b 13. a 14. r 15. Enter ;; Type ! to replace all matches in the buffer: 16. Shift 17. 1 > and a lot more keys off the home row. Four keys at once is quite a bit slower for many people than two or even three. Yes, indeed. The Emacs default key bindings are not the most ergonomic ones. To be fair though, the more common operation is M-% (Alt+%) which is a three finger chord. Also, if one dislikes a four finger chord, there are other alternatives. For example, https://news.ycombinator.com/item?id=26435874 https://news.ycombinator.com/item?id=26435874 . Or one can customize Emacs and map regex-based replacement to a more convenient key sequence.: (defun query-replace-regexp-from-top () (interactive) (goto-char (point-min)) (call-interactively 'query-replace-regexp)) (global-set-key (kbd "C-c C-r") 'query-replace-regexp-from-top) With that, the key sequence is now C-c C-r f.. <enter> bar <enter> ! which is 13 key strokes. I know I am violating my own assumption of "no customization" in this thread so far. If we allow customization, both Vim and Emacs can do very amazing things. Having said that, I just use C-M-% when I do need regex-based search and replace. Otherwise, for most situations M-% suffices. By the way, I am not claiming in my comments that the default Emacs key-bindings are superior to Vim. If we go back to where this thread started (https://news.ycombinator.com/item?id=26431864 https://news.ycombinator.com/item?id=26431864), I was only trying to show that a simple string replacement in Emacs is not as ridiculously complicated as the humorous image post in that comment made it out to be. In my experience, the vanilla Vim key strokes are more convenient in some areas (e.g., o, O, gg, G, etc.) and the vanilla Emacs ones at other areas (e.g., C-x C-o for delete-blank-lines, M-\ for delete-horizontal space, M-q for fill-paragraph that I like quite more than Vim's gqq or gqap). If we talk about key sequences only, I don't think there is a clear winner. But if we start talking about functionality, extensibility, and customizability, that would be a whole different discussion where Emacs has a lot to offer.
- Scarbutt 6y agoThere's is also replace-regexp which doesn't ask for confirmation but doesn't have a default keybinding.