――I wanted to know more about Vim, so I wrote a Vim Plugin in Python (I'm using Neovim ...) --The first Vim Plugin in my life
--This is https://github.com/shase/passgen.vim --Just generate a password with the specified digit and insert it into vim's buffer
.
├── autoload
│ └── passgen.vim
├── plugin
│ └── passgen.vim
└── python3
└── passgen.py
--If you just want to run it as a Plugin, you should have at least 3 files. ――Of course you should also have a test --If you want to publish it, you should also match doc, README and LICENCE.
python3/passgen.py
import secrets
import string
def passgenvim_generate_password(size=''):
chars = string.ascii_letters + string.digits
return ''.join(secrets.choice(chars) for x in range(int(size)))
autoload/passgen.vim
let s:save_cpo = &cpo
set cpo&vim
py3file <sfile>:h:h/python3/passgen.py
python3 import vim
function! passgen#passgen(size)
python3 vim.command("call setline('.', '%s')" % passgenvim_generate_password(vim.eval('a:size')))
endfunction
let &cpo = s:save_cpo
unlet s:save_cpo
plugin/passgen.vim
let s:save_cpo = &cpo
set cpo&vim
command! -nargs=1 PASSGEN call passgen#passgen(<f-args>)
let &cpo = s:save_cpo
unlet s:save_cpo
OK like this
Recommended Posts