-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vim-rouletterc
33 lines (28 loc) · 986 Bytes
/
.vim-rouletterc
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
"Function for getting random numbers
function! Randnum(max) abort
return str2nr(matchstr(reltimestr(reltime()), '\v\.@<=\d+')[1:]) % a:max
endfunction
"feel free to change this to your language
"alphabet of ascii characters from [a-z]
let alphabet = map(range(char2nr('a'), char2nr('z')), 'nr2char(v:val)')
"Create a map of all keys [a-z]
let keyhash = {}
for i in alphabet
let keyhash[i] = 0
endfor
"Now iterate over the map, and set it to a random key
for key in keys(keyhash)
"look for a random letter that hasn't been used yet
while 1
let pos = Randnum(26)
let newkey = keys(keyhash)[pos]
"Removing used keys and the same key (because that would be lame)
if keyhash[newkey] == 1 || key == newkey
continue
endif
break
endwhile
"Note: The only way to set dynamic bindings is via `execute [binding command as string]`
execute "noremap ". newkey . " " . key
let keyhash[newkey] = 1
endfor