Skip to content

Instantly share code, notes, and snippets.

@garethrees
Created December 10, 2020 15:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garethrees/4157f697784658e711aaf0912fb9ae17 to your computer and use it in GitHub Desktop.
Save garethrees/4157f697784658e711aaf0912fb9ae17 to your computer and use it in GitHub Desktop.
Vim macro for erb gettext strings

I’m currently adding translation markup to a load of files. Here’s a before/after:

- <h3>Need to protect your scoop?</h3>
+ <h3><%= _('Need to protect your scoop?') %></h3>

Using vim-surround, this takes a few steps:

  1. ysit' (surround in tag with single quote)
  2. ysa') (surround the single quotes with parenthesis
  3. ysa(= (surround the parenthesis with erb tags)
  4. Manually insert _ before the first paren

You can then run the macro on lines matching a pattern with something like

:g/pattern/norm! @a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment