Skip to content

Instantly share code, notes, and snippets.

@javipolo
Last active November 9, 2016 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javipolo/db56a1e0b017f3e9648685020d48c917 to your computer and use it in GitHub Desktop.
Save javipolo/db56a1e0b017f3e9648685020d48c917 to your computer and use it in GitHub Desktop.
eyaml encrypt within vim
" Write eyaml encrypted pass directly
" http://github.com/javipolo
"
function! Eyaml_input()
call inputsave()
let my_pass = input('Secret: ')
call inputrestore()
let encpass = system("eyaml encrypt -o string -q -s ".shellescape(my_pass)." 2>/dev/null")
call append(line('.'), split(encpass, '\v\n'))
join
endfunction
function! Eyaml(type)
if a:type ==# 'v'
" We are in visual character mode
execute "normal! `<v`>y"
elseif a:type ==# 'char'
" We are in normal mode
execute "normal! `[v`]y"
else
return
endif
let cmd = "eyaml encrypt -o string -q -s ".shellescape(@@)." 2>/dev/null"
let encpass = split(system(cmd),'\v\n')[0]
if a:type ==# 'v'
execute "normal! `<v`>s".encpass
execute "normal! `<"
elseif a:type ==# 'char'
execute "normal! `[v`]s".encpass
execute "normal! `["
endif
endfunction
nnoremap <silent> <Leader>E :call Eyaml_input()<CR>
nnoremap <silent> <Leader>e :set operatorfunc=Eyaml<cr>g@
vnoremap <silent> <Leader>e :<C-U>call Eyaml(visualmode())<CR>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment