I've been using the solution from this gist with Vim for years, so when I moved to NeoVim, I translated it to Lua, and it still works:
local gpgGroup = vim.api.nvim_create_augroup('customGpg', { clear = true })
-- autocmds execute in the order in which they were defined.
-- https://neovim.io/doc/user/autocmd.html#autocmd-define
vim.api.nvim_create_autocmd({ 'BufReadPre', 'FileReadPre' }, {
pattern = '*.gpg',
group = gpgGroup,
callback = function ()
-- Make sure nothing is written to shada file while editing an encrypted file.
vim.opt_local.shada = nil
-- We don't want a swap file, as it writes unencrypted data to disk
vim.opt_local.swapfile = false
-- Switch to binary mode to read the encrypted file
vim.opt_local.bin = true
vim.cmd("let ch_save = &ch|set ch=2")
end
})
vim.api.nvim_create_autocmd({ 'BufReadPost', 'FileReadPost' }, {
pattern = '*.gpg',
group = gpgGroup,
callback = function ()
vim.cmd("'[,']!gpg --decrypt 2> /dev/null")
-- Switch to normal mode for editing
vim.opt_local.bin = false
vim.cmd('let &ch = ch_save|unlet ch_save')
vim.cmd(":doautocmd BufReadPost " .. vim.fn.expand("%:r"))
end
})
-- Convert all text to encrypted text before writing
vim.api.nvim_create_autocmd({ 'BufWritePre', 'FileWritePre' }, {
pattern = '*.gpg',
group = gpgGroup,
command = "'[,']!gpg --default-recipient-self -ae 2>/dev/null",
})
-- Undo the encryption so we are back in the normal text, directly
-- after the file has been written.
vim.api.nvim_create_autocmd({ 'BufWritePost', 'FileWritePost' }, {
pattern = '*.gpg',
group = gpgGroup,
command = 'u'
})
(gist)
It is far from optimal, and I'm open to suggestions for improving it!
gpg-agent
as suggested by tarruda (NeoVim author) in that thread from Github you linked?set shellpipe
in Vim, you'll see similar problems. I've been contemplating whether it would be better to write a new plugin for neovim, since the current one would need a fair amount of refactoring to work nicely with neovim.