A short howto to get Vim to conceal passwords, while still having them selectable and copy-paste-able. You can get the passwords visible by visual-selecting them in Vim.
YMMV how well this works for you and your terminal. Please (auto)encrypt and (auto)versioncontrol your passwordfiles, to prevent mistakes. Please note your passwords may stick in clipboard managers like Klipper.
This solution uses vim modelines, syntax overrides and the conceal
function in Vim.
at the top of your passwordfile:
# vim: noswapfile noexpandtab filetype=gpgpasswordfile nosmarttab noai
in your .vimrc:
- set the conceallevel for our self-defined
gpgpasswordfile
filetype
autocmd FileType gpgpasswordfile set conceallevel=1
- define/overload the
Todo
syntax definition to include everything following a doubletab, not including the doubletab. Replace with pleasing Unicode char or whatever
autocmd FileType gpgpasswordfile syntax match Todo /\v\t\t.*/hs=s+2 conceal cchar=❆
- set the color of the
Todo
syntax definition to red on red, explicitly
autocmd FileType gpgpasswordfile hi Todo ctermbg=darkred ctermfg=darkred guifg=#d14a14 guibg=#d14a14
- set the color of the
Visual
syntax definition to something hard to read, but readable (if you really need to see the password on your screen).
autocmd FileType gpgpasswordfile hi Visual gui=NONE guibg=white guifg=black ctermbg=white ctermfg=black term=bold cterm=bold gui=bold
refinements welcome.