I want to be able to easily start Vim in a private mode. Let's define a private mode as one that utilizes this set of commands:
set history=0
set nobackup
set nomodeline
set noshelltemp
set noswapfile
set noundofile
set nowritebackup
set secure
set viminfo=""
Let me know if you can think of any additional commands suitable for the private mode.
The point is I cannot think of any short and easy way to start Vim with this setup.
Here are some ideas I've come up with:
Load .vimrcprivate instead of .vimrc
You can simply put all the necessary commands into .vimrcprivate and start Vim like this:
vim -u .vimrcprivate
Define and call a
Private()
functionAnother idea add a code like this to your .vimrc:
function Private() " set of commands here endfunction
and then you are able to start Vim in a private mode like this:
vim -c 'call Private()'
Use a variable to trigger the setting up of your commands
It is quite similar to the second solution. Just add
if exists('privatemode') " set of commands here endif
to your .vimrc and then start Vim using
vim -c 'let privatemode=1'
which is neither smart nor short.
Add an alias to your .bashrc (or to any other .*rc file your shell is using)
For example:
alias vimprivate="vim +\"set history=0\" +\"set nobackup\" +\"set nomodeline\"\ +\"set noshelltemp\" +\"set noswapfile\" +\"set noundofile\"\ +\"set nowritebackup\" +\"set secure\" +\"set viminfo=\"\"\""
which is awful. I don't like it.
Use an environmental variable
Just run
VIM_PRIVATE=1 vim
and addif $VIM_PRIVATE " set of commands here endif
to your .vimrc.
Some magic (from a comment by Carpetsmoker in this thread)
Carpetsmoker says in this comment that
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 &cryptmethod != "" | setlocal nobackup noundofile ... | endif
should do the magic for you, and it's impossible to forget.However I've got no idea how this magic works yet.
Have you got any idea?
The perfect solution would be vim -private
or vim +Private
however:
- I am quite sure you cannot add you own custom command line options like
-private
. - when it comes to
+Private
I was unable to find it online.
command! Private set history=0 nobackup secure ...
, and then call it from the shell withvim +'Private'
. Concerning the last autocommand you mentioned, when a buffer is read, it tests whether the value of the'cryptmethod'
option, or'cm'
for the short version, is non empty. This option controls the encryption method used to encrypt the buffer when it's written to a file with the Ex command:X
. If the option is not empty, then the autocommand sets up various options.vim -Nu .vimrcprivate
.alias vimprivate='vim -u .vimrcprivate'
etc.v:progname == "vimp"
and if true, execute your private-mode settings. See:help v:progname
.