You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在VIM中配置元音字母后跟’的自动替换规则(含E/e例外)

Custom Accented Character Replacement for Vim

Hey there! Based on your specific replacement rules (even though it’s not strict Italian orthography, it’s a solid starting point), here’s how you can set up the <leader>-triggered normal-mode mapping in your .vimrc to handle all those accented characters automatically:

The Full Mapping

Drop this line right into your .vimrc file:

nnoremap <leader>r :%s/\v(^|\s)([eE])'/\1\=toupper(submatch(2)) ==# 'E' ? 'È' : 'è'/g | %s/\v([^[:space:]])[eE]'/\1\=toupper(submatch(2)) ==# 'E' ? 'É' : 'é'/g | %s/\v([aAiIoOuU])'/\=submatch(1) ==# 'A' ? 'À' : submatch(1) ==# 'a' ? 'à' : submatch(1) ==# 'I' ? 'Ì' : submatch(1) ==# 'i' ? 'ì' : submatch(1) ==# 'O' ? 'Ò' : submatch(1) ==# 'o' ? 'ò' : submatch(1) ==# 'U' ? 'Ù' : 'ù'/g<CR>

How It Works (Breakdown)

Let’s walk through each part so you know exactly what’s happening:

  • First substitution: Handles the e/E exception for leading cases. It matches e' or E' that comes right after a line start (^) or space (\s), then replaces it with è or È respectively, stripping the single quote.
  • Second substitution: Takes care of non-leading e/E cases. It matches e' or E' that follows any non-space character, replacing it with é or É.
  • Third substitution: Handles all a/i/o/u (uppercase and lowercase) cases. It matches any of these letters followed by a single quote, then swaps them out for their corresponding accented versions (àìòùÀÌÒÙ) and removes the quote.

Quick Notes

  • You can replace <leader>r with any trigger key combo you prefer (e.g., <leader>a for "accents")—just swap out the r for your key of choice.
  • This runs on the entire file (% range) when you press the leader combo in normal mode. If you want to run it only on a selected range, you can adjust the mapping to use '<,'> instead of %, but the current setup works great for full-file fixes.

内容的提问来源于stack exchange,提问作者Michele

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 04:03:30