Log in
Seblog.nl

Seblog.nl

So at one point I proudly admitted to a co-worker that I knew how to search and replace in Vim: I did /foo, then ciw, bar, and escape (changing the inner word to 'bar', or whatever the right replacement motion would be) and then press n and . for the number of times I needed to (first one goes to the next occurrence of 'foo', and the period key repeats the last edit, which is magic and very powerful in itself).

He replied with a less interesting, but in some cases more appropriate way of doing it: :%s/foo/bar/gc. This command takes the current file (%), and substitutes 'foo' for 'bar', with a flag for global (more than once) and choice. Vim will then stop at each 'foo' and gives you choices for 'y' or 'n' (and others), so you can interactively pick your replacements.

Today I leaned about the gn text object. Where iw stands for 'inner word', gn stands for 'go next'. So one can type /foo, then cgn, bar, and escape, which is almost the same. But then you can just keep hitting ., and it will perform the last action on the next occurrence of 'foo'. No need for n anymore!

I mean if you want to be presented with a choice for each replacement, go use :%s, but this gn thing is darn cool.

Nog steeds ben ik verbaasd als mensen die jonger zijn dan ik een auto hebben. Gaat dat ooit over?

Maybe I should start a Vim-log of things I encounter and find useful. Most of them seem too advanced for the beginner and too trivial for the expert, but who's really an expert at Vim, aren't we all beginners for some part of it?


So, today I learned about the :cd command, which I instantly memorized (for it's just Unix). It changes the home directory of Vim, (by default this is the folder you start Vim in).

For example, if you're at ~/code and you want to check the contents of some file in my Seblog-project, I would do vim seblog/site/config/config.php. But as always, I need to check another file, so I use :e (short for :edit) to open that file, but because I was in ~/code when I opened Vim, I need to type: :e seblog/site/config/other-file.php. I find that annoying, so I would close Vim altogether, cd seblog and then vim ..

Now, I would just :cd seblog and then :e site/config/other-file.php. Or use :Ex (for :Explore) if I wanted to look around, but I knew that one already.

Het fijne aan richting aanwijzen met je handen i.p.v. met een lichtje is dat je er veel meer nuance in kan leggen. ‘Ik ga zo hierheen.’ ‘Ik ga nu.’ ‘Je begreep het waarschijnlijk al uit de verkeerssituatie, maar inderdaad, ik ga hier naar links.’

Ik ga wel gewoon lekker thuis de literator uithangen met een bak sinaasappelkwark en De ontdekking van de hemel.

Het voordeel van het feit dat ik heel nodig de was moet doen, is dat ik eindelijk wat administratieve dingen wegwerk.

Je herkent de tot elektrische fietser bekeerde automobilist aan hun gewoonte om precies in het midden van het fietspad te blijven fietsen. Ze halen ook in via het midden van de tegenliggende rijstrook.

Meer laden