Search code examples
sublimetext3sublimetextsublime-text-pluginsublimetext-snippet

Snippet to replace accented vowel by vowel without tilde in sublime text


In the following snippet of LaTeX package (sublime text 3) every time I enter a: Space, . (dot), ?, *, #, Is replaced by "_" character in the part \label{sec:*****} and % section ***** (end). Also replaces capital letters to lowercase. Here the snippet:

<snippet>
<content><![CDATA[
\section{${1:section name}} % (fold)
\label{sec:${2:${1/\\\w+\{(.*?)\}|\\(.)|(\w+)|([^\w\\]+)/(?4:_:\L$1$2$3)/g}}}
${0:$TM_SELECTED_TEXT}
% section $2 (end)
]]></content>
    <tabTrigger>sec</tabTrigger>
    <scope>text.tex.latex</scope>
    <description>Section</description>
</snippet>

My question is: how can I change? the snippet to replace accented vowel by vowel without tilde, ie, if I use the snippet the result is:

\section{acción además menú aquí acné} % (fold)
\label{sec:acción_además_menú_aquí_acné}

% section acción_además_menú_aquí_acné (end)

but I want to get the following:

\section{acción además menú aquí acné} % (fold)
\label{sec:accion_ademas_menu_aqui_acne}

% section accion_ademas_menu_aqui_acne (end)

Solution

  • You can do this by manually specifying the characters to find and what to replace them with. This is because ST unfortunately doesn't seem to support the POSIX character equivalents.

    Using the following snippet:

    <snippet>
    <content><![CDATA[
    \section{${1:section name}} % (fold)
    \label{sec:${2:${1/(?i:(á)|([éę])|(í)|(ó)|(ú)|(ń))|\\\w+\{(.*?)\}|\\(.)|(\w)|([^\w\\]+)/(?{10}_:\L$7$8(?1a:)(?2e:)(?3i:)(?4o:)(?5u:)(?6n:)$9)/g}}}
    ${0:$TM_SELECTED_TEXT}
    % section $2 (end)
    ]]></content>
        <tabTrigger>sec</tabTrigger>
        <scope>text.tex.latex</scope>
        <description>Section</description>
    </snippet>
    

    typing sec Tab and typing/pasting in acción además menú aquí acné ńę, for example, will result in:

    \section{acción además menú aquí acné_ńę} % (fold)
    \label{sec:accion_ademas_menu_aqui_acne_ne}
    
    % section accion_ademas_menu_aqui_acne_ne (end)
    

    For more information on the replacement format syntax, see http://www.boost.org/doc/libs/1_56_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html