Sometimes it's not clear if you should use a macro or a plugin for a common editing task. There are things that I'll instinctively create a macro for (:help complex-repeat), and others that are broad enough to be made into plugins. In those cases it's often best to search for a plugin first.

Here's one such example: Mark Volkmann's vim-js-arrow-function (GitHub: mvolkmann/vim-js-arrow-function). It's a small plugin, but does something broad enough that is safely tucked away in a plugin -- it turns anonymous JavaScript functions into their "fat arrow" equivalents.

In JavaScript you commonly pass anonymous functions to methods, like this:

var a = [

var a2 = { return s.length });

But JavaScript is evolving and now (kind of, you'll generally need a transpiler) supports "arrow" functions:

var a3 = => s.length);

Mark's script lets you switch to this syntax with the JsAnonFnToArrowFn command. The source is commented so you can figure out how it works and make your own language syntax changing scripts.

blog comments powered by Disqus