8

我知道VIM支持有向图,如果可以使用:s命令就完美了,但我找不到使用它的方法!

我认为是这样的:

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

会很完美,但我没有找到digraph功能。提前致谢。

编辑
好的,在对内置 VIM 的功能进行了一些研究之后,我发现tr了该问题的第一个解决方案:

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

但是,我仍然想知道是否有一种digraph在表达式中使用的方法:)

4

2 回答 2

5
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

于 2013-09-10T18:40:17.813 回答
2

这是使用手动编码的 vim 函数的另一种方法(添加到您的 vimrc):

" get a matching digraph for a given ASCII character
function! GetDigraph(var1)
   "incomplete dictionary of digraphs, add your own....
   let DigDict = {'a': 'à', 'e': 'è', 'i': 'ì'}
   "get the matching digraph.  If no match, just return the given character
   let DictEntry = get(DigDict, a:var1, a:var1)
   return DictEntry
endfunction

像这样称呼它:%s/\([aeiouAEIOU]\)'/\=GetDigraph(submatch(1))/g

于 2013-09-10T15:46:06.007 回答