Hacker News new | ask | show | jobs
by milesrout 481 days ago
Multiple cursors is a good alternative to recording a macro and executing it on multiple lines. But vim isn't good because of that. It is good because it is a language of simple but composable text objects and manipulations: ciw, dd, ci", gv, vapcU, gqip, and plugins that expand this language to add additional text objects. I have one installed that lets me use a function argument as a text object, so I can do something like da, and it will delete the argument (even if it is a complex expression) under my cursor, and then I can paste it elsewhere later. But I can compose that with anything. I could compose that with vim-surround, so that I could quote it: ys"i,

And of course there is also search and replace and lots of excellent plugins, which crucially work today as well as they worked 15 years ago. Tabularize is a vim plugin that lets me do things like realign

    foo: bar
    fang: wizz
with a space before bar, to make bar and wizz aligned. This is very convenient, and it is designed around vim's powerful regular expressions so that you can use it to align all sorts of data even if it uses weird delimiters or the delimiters are totally contextual.

This isn't programming your editor live, it is just composition of simple elements you learn gradually. At first it is just navigating from the home row (mice suck, especially on laptops), and dd to delete lines etc. Then you learn new text objects and new effects over time, and your O(m+n) work in learning them has O(mn) results.

1 comments

Vim's composability is awesome. But it turns out that its possible to take this a lot further than vim does: http://www.willghatch.net/blog/text-editing/composiphrase_co...