Dup Ver Goto 📝

Why I Love Vim 1

pt2/editor editor vim 10-25 06:23:40
To
34 lines, 429 words, 2462 chars Wednesday 2023-10-25 06:23:40

Vim has a hard initial learning curve. It's not intuitive. It trades off the initial learning curve and intuitiveness for efficiency in getting stuff done.

With practice the keystrokes become muscle memory. Then you find it more efficient, by far, than other editors. But you have to get over that initial learning curve.

For example, using hjkl instead of cursor keys means not moving your fingers from the home row. You can define jk to be an alias for escape in insert mode. That means you don't have to move your fingers from the home row to exit insert mode. (You rarely type a j followed by a k, and for those you press j, wait a second, then press k.)

It probably makes less sense if you don't touch type. I find myself wanting to use vim keystrokes even when using other editors, they've become that natural and automatic.jk

For example, to find every line containing function ( and then append the characters // this is a function to those lines, you can type

:g/function (/s@$@ // this is a function

and then press enter. Or to take the contents of a line (say XYZ) and replace it with mv -vn "XYZ" "NewName_" you can type

:%s/.*/mv -vn "&" "NewName_

then manually append the unique bit of each line, and then

:%s/$/.m4a"

to append .m4a to each line. This is great for those cases when a power rename using a regex isn't possible.

I can literally do complex edits like this over ten times faster than using e.g. VS Code. Then, sometimes, the only choices are vim and nano. And once you know vim, nano is over an order of magnitude slower for common tasks.

Then you can define your own shorthands, some specifically for certain filetypes. For example in Javascript, when inserting text, if I type ce( this immediately expands to document.createElement( and likewise ae( expands to addEventListener( which saves a lot of typing. And imap, nmap, vmap (and the noremap variants) mean that you can define e.g. \h so that pressing \h in normal (i.e. non-insert) mode, this presses /function (<cr>f(lci( This incantation (an artificial one off the top of my head), finds the next line with function ( in it, moves the cursor within the (parens), and then deletes the text between those parens, and switches to insert mode so that you can type something else to go between them.

And it goes on. Neovim then goes further, allowing you to use Lua as the extension language.

:wq