I’m working on a website and we decided to localize it using GNU gettext. Soon enough I found it tiring to wrap each string manually in _(
and )
and also to do it in Smarty (using {t}string{/t}
. So I decided that I need a macro that will let highlight the string that needs translation and the macro will wrap for me.
I ended up writing two macros one for PHP files (but it’s also good for C/C++ etc.) and one for smarty.
:vmap tg di_(<ESC>pa)<ESC> :vmap ts di{t}<ESC>pa{/t}<ESC>
To use these macros just highlight the string for translation in vim’s visual mode and press tg
(or ts
), and your string will be wrapped for translation.
Hi,
thanks for the idea. I was thinking about adding a mapping myself but wanted to check what others did in this area. I’ve ended using:
:vmap tt “tdi_(t)
Which works better for me because it doesn’t play with the default buffer 🙂
/Janusz
Isn’t this easier (stay on the first quote char):
df’i_()PF’
It looks like a nice solution.