Hacker News new | ask | show | jobs
by chousuke 3407 days ago
It's not the shortcuts, it's how they work. The thing about vi shortcuts is that they form a composable "language" of sorts, so instead of having to memorize a set of shortcuts for doing specific things, you memorize motions and actions and the rules to compose these.

For example, in another editor you might have ctrl-K to delete a line (dd in vim) , but what about deleting 4 lines? in vim, it's 4dd.

Or you might want to delete from the start of a block to the end... The motion for block in vim is %, so to delete a block, you'd do "d%". Similarly, deletion to the end of the line is d$

In visual block mode (ctrl-v) you can select a bunch of text and apply an action (eg. a simple replace, which would be :s/foo/bar) on only that text.

Even if you just learn a bit at the surface, the free composability of motions with actions makes even classic vi (which doesn't even support arrow keys for moving around) extremely comfortable to use, and most of the time you don't need to twist your hands into uncomfortable chords involving multiple modifier keys.

1 comments

"Another editor" presumably means Emacs, but isn't Vi vs Emacs dead? In 2017, the argument is really Vi-or-Emacs vs other editors.

In Emacs, deleting four lines is Alt-4 Ctrl-K, usually written M-4 C-K.

One way to delete a whole block (meaning a paragraph?) is M-h Backspace. Deletion to the end of the link is C-K.

Selecting a region is done with C-Space, running a simple replace is then M-% foo bar !

I'm not an expert with Emacs. The most useful function I use is the macros, which saves me learning many other functions. F3 starts macro recording, F4 ends it, then F4 again runs the macro. It's easy to script changes and run them in this way.

Ctrl-K is just what came to mind. I think it works in both nano and emacs, and the mnemonic is "kill"

Emacs is without a doubt superior technology when compared to vim. There are perfectly usable vi clones that run on Emacs, after all. The main benefit vi has over emacs is that it's everywhere (except windows :() in some form, so even on a completely unfamiliar machine away from your highly developed dotfiles, your muscle memory still works to an extent.

The main reason I don't use an Emacs implementation of vi is that muscle memory is really bothersome to retrain, and the differences are enough to disrupt my workflow rather badly when using eg. Spacemacs. I just haven't found the benefits to be significant enough to outweigh the inconvenience of retraining myself.