-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcycle_unicode_characters_in_insert_mode.vim
40 lines (38 loc) · 1.21 KB
/
cycle_unicode_characters_in_insert_mode.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
" Create a mapping that can be used in insert mode or normal mode to cycle
" through a predetermined list of alternative unicode characters.
"
" Each sublist is a list of characters that will be cycled through when the
" mapping is pressed. If the same character appears in more than one of these
" lists, bad things will happen.
let g:unicode_list = [
\ [ 'a', 'à', 'â', 'ä' ],
\ [ 'A', 'À', 'Â', 'Ä' ],
\ [ 'e', 'é', 'è', 'ê', 'ë' ],
\ [ 'E', 'É', 'Ê', 'È', 'Ë' ],
\ [ 'i', 'î' ],
\ [ 'I', 'Î', 'Ï' ],
\ [ 'o', 'ô', 'ö' ],
\ [ 'O', 'Ô', 'Ö' ],
\ [ 'u', 'û', 'ù', 'ü' ],
\ [ 'U', 'Û', 'Ù', 'Ü' ],
\]
function! s:CycleUnicode(mode)
let char = matchstr(getline('.'), '.', col('.')-1)
for sublist in g:unicode_list
let idx = index(sublist, char)
if idx >= 0
try
let char = sublist[idx+1]
catch /E684/
let char = sublist[0]
endtry
execute "normal! r" . char
break
endif
endfor
if a:mode == 'i'
startinsert
endif
endfunction
inoremap <f12> <esc>:call <SID>CycleUnicode('i')<enter><right>
nnoremap <f12> :call <SID>CycleUnicode('n')<enter>