jueves, 24 de febrero de 2011

Vim macros

I'm a total noob with vim, so I'm going to start a very basic series of blog posts writing down everything I learn :) Those are going to be very short posts explaining a vim feature. So, let's get started.

Today, I've been working with Tooky the whole day and he has taught me how macros work in Vim.
I can only imagine how powerful they are :D We've used one to rename a method (including everyplace it was called)

How to record a macro
First of all, we need to be on command mode. Then, we have to press 'q' and the key to store the macro ('qa' will store the macro in the key 'a'). We'll see the word 'recording' on the last line.

Everything we do then will be recorded (And I mean everything and on any mode).

To stop recording the macro, all we need to do is press 'q' on command mode.

How to execute a macro
All we have to do is to press 'q' and the key where we stored the macro (on command mode). To execute a macro stored in the key 'a' we have to press '@a'.

Recursive macros
We can make a recursive macro by recording a '@<key that stores the macro>'

Hope you find it useful :)

1 comentario:

  1. Hi mister Peña :)

    Vim macros seem very useful! I can imagine routine ugly operations stored in a macro and you just press a key, awesome! (sound like refactoring indeed...)

    I'm sure when I will use Vim your posts will be great step by step guide for me. Thanks!

    Keep on mate! ;)

    ResponderEliminar