basically i want to test within my vimrc, if /home/$USER/.dotfiles/nvim/bundle/vim-snippets/snippets was symlinked to /home/$USER/.dotfiles/nvim/snippets If not, it should create the symlink.

the code:

au VimEnter * :!bash -c "! [  -L /home/$USER/.dotfiles/nvim/snippets  ] && ln -sb /home/$USER/.dotfiles/nvim/bundle/vim-snippets/snippets /home/$USER/.dotfiles/nvim/snippets"

The ":" before !bash doesn't change anything.

the error message:

Error detected while processing VimEnter Auto commands for "*":                                                                                              
E34: No previous command  

My problem is, i don't know what is wrong with my code and google/help pages also aren't very helpful.


! has to be escaped which can be done with a backslash \!.

I think the problem comes from the second bang in your command which has a special meaning for vim. It is automatically replaced with the previous external command.

Any '!' in {cmd} is replaced with the previous external command (see also 'cpoptions'). But not when there is a backslash before the '!', then that backslash is removed. Example: ":!ls" followed by ":!echo ! ! \!" executes "echo ls ! !".

And since the autocommand is triggered by the VimEnter event, which means as soon as vim is launched, there can't be any previous external command.

You should probably escape the second bang to protect it from being interpreted by vim before the command is sent to the shell :

au VimEnter * :!bash -c "\! [  -L /home/$USER/.dotfiles/nvim/snippets  ] && ln -sb /home/$USER/.dotfiles/nvim/bundle/vim-snippets/snippets /home/$USER/.dotfiles/nvim/snippets"

For more information, see :help :!.

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.