How to use it:

First of all you just need to record a macro assigning it to a named register. It's done by starting the macro typing q<register> (ex.: for register e , type qe ) performing your actions, and then, stop recording typing q .

After that, the sequence of your commands will be recorded on register and you'll use it simply typing @<register> (ex.: @e ).

Creating the 'to ES6 arrow function' converter:

First of all, open a new example.js file and write the sample functions below:

Now we'll start recording our macro on register e , convert the first function to ES6 arrow function syntax, and stop recording.

(Before start: Make sure your cursor is sitting on line 1 and you're on NORMAL mode. Be aware that you can perform the actions on your own pace, no rush, there's no time interruption.)

Here's the sequence explained:

qe — start recording macro on register e (you'll notice that you'll get a message under your statusline indicating that recording is on)

0 — move cursor to the first column

— move cursor to the first column :s/var/const/g and hit enter — substitute var by const

and hit enter — substitute by :s/function//g and hit enter — find the word function and remove it

and hit enter — find the word and remove it % — move cursor to the character )

— move cursor to the character a — enter on INSERT mode with the cursor after character )

— enter on INSERT mode with the cursor after character hit <Space> and type => — insert the arrow syntax

and type — insert the arrow syntax hit <Esc> — go back to NORMAL mode

— go back to mode 0 — move cursor back to the first column

— move cursor back to the first column q — stop recording macro

Now you're done, if you access your registers you'll see that the sequence of your commands are stored on register e . It's the macro!

Using the macro:

To use the macro, you just move the cursor to the line you want it to act and simply type @e .

Right now we could just jump to line 5 and apply it to byeFunc function as well (and you can try it right now), but on this example I'll show some more efficiency of our newly created macro, using it combined with some other commands.

Let's make the macro be applied in all functions of the file on a single shot!

First of all, hit u to undo the function's transformations until you have the first function state the same as before recording the macro:

Even after undoing the changes, you can check your registers and you'll see that your macro is already there:

Now, apply the command :g/function/normal @e :

Use the macro created to search all functions and replace by arrow functions

Combining these commands basically you're telling vim to find any line that has the word function and apply the macro recorded on register e .

(To know more about macros, global or normal command, hit the :help <command> . Make sure you get used to :help section visiting it very often)