To add to this stackoverflow question, what should one put in their .vimrc to ensure 'private editing' of certain file extensions (e.g. .gpg files).

Without compromising the effectiveness of the session, no info about work done should be saved, including registers, search history, command history, views, swaps, etc. For gpg files, one can use this vim plugin, but besides editing the plugin, how would one extend these discussed ideas to arbitrary file types?

We'll probably make use of the following commands,

if <ft in privacy_ext_list>
  set noswapfile
  set noundofile
  set viminfo=

but besides the appropriate conditional statement, what's missing?

Further, is there a way with Vimscript to make an array of file extensions and then evaluate if the current filetype is within the array?

  • 6
    @Carpetsmoker I think this question is broader. The author is not just asking how to set parameters in a buffer of a particular filetype, but to a certain extent what parameters to set to ensure privacy. That's certainly not obvious or collected together in a central place, so I think it makes a good question. Feb 16 '15 at 8:42

Here is the full list of settings which should be added to your .vimrc if you want to prevent any leakage of sensitive files.

set nobackup
set nowritebackup
set noundofile
set noswapfile
set viminfo=""
set noshelltemp
set history=0
set nomodeline
set secure

I recommend you create a new configuration file called .vimrc_secure and run Vim with vim -u ~/.vimrc_secure (or create a script/alias) when you want to edit your sensitive file. This will minimize the risk of a malicious plugin or buggy feature.

  • I like this in the sense that .vimrc_secure is independent of the .vimrc(as doing as you say then allows the user to :e private file [thus keeping the file out of the shell history as well]), but using vim -u ~/.vimrc-incognito will not source ~/.vimrc at all, correct? The joys of privacy should not come at the cost of reduced comfort (unless the comfort is fundamentally flawed via malicious plugin or buggy feature). While there should be an emphasis on the risk of unknowns, surely, there must be some way to conditionally wrap your solution...
    – HAL 9001
    Feb 19 '15 at 17:47
  • 1
    I would not recommend using a separate vimrc file, for the simple reason that it's so easy to forget. Something like this autocmd: au BufRead * if &key != "" | setlocal nobackup noundofile ... | endif should do the magic for you, and it's impossible to forget. Feb 25 '15 at 16:52
  • @Carpetsmoker, what's the &l:cm != "" all about?
    – Wildcard
    Jan 20 '16 at 21:22
  • 1
    @Wildcard Ehm.... Look like I intended &cryptmethod, which refers to that setting. The l: part was a mistake (I used my special mod powers to edit my comment). Thanks for pointing that out! Jan 20 '16 at 22:24
  • @Carpetsmoker, could you please elaborate on your comment? I've created a thread here: vi.stackexchange.com/questions/6195/… Jan 20 '16 at 22:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.