aboutsummaryrefslogtreecommitdiffstats
path: root/plugin/uuid_anchor.vim
blob: 9da2cebae22b4740c5539697a1f0ae471e6d87e2 (plain)
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
" UUID Anchor vim plugin
" Language:     Python (ft=python)
" Maintainer:   VG <vg@devys.org>
" Version:      Vim 7 (may work with lower Vim versions, but not tested)
" URL:          http://git.devys.org/vim-uuid-anchor

" Only do this when not done yet for this buffer
if exists("g:loaded_uuid_anchor_ftplugin")
    finish
endif
let loaded_uuid_anchor_ftplugin = 1

if has('python')
" python2 is available
function! CreateAnchorUUID()
python << EOF
import vim
import random
generated_uuid = '{:08X}'.format(random.randint(0,256**4))
vim.current.line += generated_uuid
vim.command(''' normal l"uye ''')
EOF
endfunction
elseif has('python3')
" python3 is available
function! CreateAnchorUUID()
python3 << EOF
import vim
import random
generated_uuid = '{:08X}'.format(random.randint(0,256**4))
vim.current.line += generated_uuid
vim.command(''' normal l"uye ''')
EOF
endif



function! CreateAnchorUUID()
python << EOF
import vim
import random
generated_uuid = '{:08X}'.format(random.randint(0,256**4))
vim.current.line += generated_uuid
vim.command(''' normal l"uye ''')
EOF
endfunction

" Add mappings, unless the user didn't want this.
" The default mapping is registered, unless the user remapped it already.
if !exists("no_plugin_maps") && !exists("no_uuid_anchor_maps")
    if !hasmapto(' CreateAnchorUUID(')
        imap <leader><leader>uuid <C-o>:call CreateAnchorUUID()<CR>
    endif
endif