Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM: Replace [aeiou]' with the respective accented letter

Tags:

vim

digraphs

I know that VIM support digraph, and it would be perfect if it's possible to use with :s command, but I can't find a way to use it!

I think something like:

:%s/\([aeiouAEIOU]\)'/\=digraph(submatch(1)."!")/g

Would be perfect, but I didn't find a digraph function. Thanks in advance.

EDIT
Ok, after a bit of diggin in the built-in VIM's functions, I've found tr and a first solution to the problem:

:%s/\([aeiouAEIOU]\)'/\=tr(submatch(1), 'aeiouAEIOU', 'àèìòùÀÈÌÒÙ')/g

However, I still want to know if there's a way to use digraph in expressions :)

like image 637
Iazel Avatar asked Sep 10 '13 15:09

Iazel


1 Answers

function! Digraph(letter, type)
    silent exec "normal! :let l:s = '\<c-k>".a:letter.a:type."'\<cr>"
    return l:s
endfunction

This function will allow you to generate any digraph you want.

It simulates typing <c-k><char><char> by running it with the normal command and assigning it to the local variable s. And then it returns s.

After this function is defined and you can use it like this.

:%s/\([aeiouAEIOU]\)'/\=Digraph(submatch(1), "!")/g

Note: This was based off of the source code for EasyDigraph

like image 110
FDinoff Avatar answered Sep 19 '22 22:09

FDinoff