Say, we want to replace one string with another, e.g., "foo" with "bar" as it appears in your image post. So assuming that we need simple string replacement, not regex-based replacement, and also assuming that we have vanilla Vim, vanilla Emacs, no customization, and US layout keyboard, Emacs seems to be at par with Vim.
On Vim: <Shift>+; (:) <Shift>+5 (%) s/foo/bar/g <Enter> (16 key strokes)
On Emacs: <Alt>+<Shift>+, (M-<) Alt+Shift+5 (M-%) foo <Enter> bar <Enter> <Shift>+1 (!) (16 key strokes)
Now I know some of you might observe that I have not counted the initial <Esc> to escape to normal mode and the final i to enter insert mode again in Vim. That is correct, however, I find that experienced Vim users keep themselves in the normal mode most of the time. The normal mode is really the normal mode and the insert mode is a special mode that they get into for short periods of time to insert text. Also, they rarely use i to enter insert mode. Instead, they usually o, O, a, A, I, c<motion>, c<text-object>, etc. to enter insert mode. Then they return to normal mode again as soon as they are done inserting text, so I don't think it is fair to count the overhead of <Esc> and i while counting Vim key strokes.
" Use ; rather than : for commands
nore ; :
nore , ;For me, editing is like using a musical instrument; you want to get to the point where you're not using much conscious thought to do things quickly. How you do that doesn't really mater to much.
Many years ago (10 maybe?) I switched to the Colemak layout to help with an RSI. That messes up the vi home row navigation keys.
For a while I tried remapping jkl but since that's not very portable to other vi-like software on my own machine.
I gave up and just used muscle memory for new locations of those keys. That works surprisingly well for me.
I like Vim but I'm pretty sure that a competent emacs user would have very similar relationship with its keyboard interface.
Shift+ctrl+<- bar
Way easier than either vim or emacs
I do '/ bar' on my emacs setup (Doom)
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.
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
You meant “Control+Alt+Shift+5 (C-M-%)”.
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.
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.
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 . 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), 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.
nnoremap ; :
I've never missed the default behaviour of ";" (to repeat the last "t"-like command), and the above has helped me tremendously void theWorldsLongestFunction(int way, int too, int many, int parameters);
Then, 0f,;;;
Is my self-approved way to jump through the parameters.However I don't mind using shift as I always press it with the opposite hand to one that's pressing the key to be shifted.
I also use a lot insert mode Ctrl commands.
I think any keyboard interface that you can use without looking at the keyboard is Ok by me.
I would probably be happy enough in emacs even with all the weird cording but I'm just too wedded to Vim at this point to want to change.
In the Emacs world, while remapping Caps Lock to Ctrl helps in reducing strain for many people, it also causes strain for some people. Every time, this discussion comes up in the Freenode #emacs channel, I have always noticed someone mentioning that remapping Caps Lock to behave like Ctrl caused them RSI.
Surprisingly, I did suffer from pain due to repetitive strain under the base of my forefinger once which seemed to be linked to overuse of mouse. The repetitive clicking, dragging and dropping in the Windows world nearly 10 years ago had taken a toll on my right hand forefinger. Taking inspiration from how we use keyboard with both hands, I then taught myself to use mouse with both hands (alternating between left hand and right hand every hour or so) and the pain gradually disappeared.
I also avoid using hjkl all the time and use the arrow keys to counter RSI.
*gcn<bar>.
That is: * (highlight all occurrences of foo)
gcn (globally changes the highlighted pattern)
<bar> (the text you want to replace with)
. (repeat the command as many times as you want).
If you know you want to change all the occurrences at once you can highlight "foo" with * (shift-8) and then use :%s//bar/g as it will be set as the last regexp.save in Vim:
[esc] : w enter
3 or 4 keystrokes involving two hands.save in emacs:
C-x-s
one 3 fingered chord with the left hand.And the chords can be hit much faster than key sequences.
Vim can be much faster because it can be adapted to the user. For me that's the whole point of using it, otherwise I might as well just use VS Code and curse at the annoyances every day.
11 keystrokes.
<Ctrl> + x + p + r "foo" <enter> "bar" <enter>
which are 12 keystrokes, if I'm not mistaken, and does more.
I'm pretty sure though that Emacs is actually short for Editor MACroS.
A nod to the fact that Emacs is really an extensible Lisp system rather than just an editor or IDE.