From 327b4c34b71173c64206439d72c7468a071f2d0c Mon Sep 17 00:00:00 2001 From: Craige McWhirter Date: Mon, 8 Mar 2021 16:10:33 +1000 Subject: [PATCH] Added ISO support --- profiles/vim.nix | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/profiles/vim.nix b/profiles/vim.nix index 9c8be10..a5103ce 100644 --- a/profiles/vim.nix +++ b/profiles/vim.nix @@ -76,6 +76,37 @@ vim_configurable.customize { autocmd BufWritePost,FileWritePost *.gpg u augroup END + " Manage ISO files + augroup iso + au! + + " First make sure nothing is written to ~/.viminfo while editing an encrypted file. + autocmd BufReadPre,FileReadPre *.iso set viminfo= + " We don't want a swap file, as it writes unencrypted data to disk + autocmd BufReadPre,FileReadPre *.iso set noswapfile + " Switch to binary mode to read the encrypted file + autocmd BufReadPre,FileReadPre *.iso set bin + autocmd BufReadPre,FileReadPre *.iso let ch_save = &ch|set ch=2 + autocmd BufReadPost,FileReadPost *.iso '[,']!gpg --decrypt 2> /dev/null + " Switch to normal mode for editing + autocmd BufReadPost,FileReadPost *.iso set nobin + autocmd BufReadPost,FileReadPost *.iso let &ch = ch_save|unlet ch_save + autocmd BufReadPost,FileReadPost *.iso execute ":doautocmd BufReadPost " . expand("%:r") + + " Convert all text to encrypted text before writing + autocmd BufWritePre,FileWritePre *.iso '[,']!gpg --default-key=A4122FF3971B6865 --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. + autocmd BufWritePost,FileWritePost *.iso u + augroup END + + " Use persistent history. + if !isdirectory("/tmp/.vim-undo-dir") + call mkdir("/tmp/.vim-undo-dir", "", 0700) + endif + set undodir=/tmp/.vim-undo-dir + set undofile + " My Markdown environment function! MarkdownSettings() set textwidth=79