Proposed tip Please edit this page to improve it, or add your comments below (do not use the discussion page).
I have found myself writing an installation script that will install a few Vim plugins (optionally) for the user. This task can be simplified using pathogen.vim. But what if the user already uses it?
More generally, the question can be stated as, "Is such-and-such-plugin already loaded for this user?"
In Bash, I was able to come up with the following command to check for the existence of the g:loaded_pathogen
variable. Unfortunately, the command did not seem to work in C Shell, so I had to wrap it in a small script.
#!/bin/bash vim -c ':exec ":silent !echo ".exists("g:loaded_pathogen") | exec ":q!"'
The script sends either 0 or 1 (plus mystery terminal control sequences) to stdout.
Checking the value inside a script is a bit more difficult due to those pesky control sequences. Vim even detects that it is about to hose you and emits, a "Vim: Warning: Output is not to a terminal" message.
Another problem that I have encountered occurs when the user's configuration loads plugins that contain errors. When this happens, it causes the "Press ENTER or type command to continue" prompt but it is no longer echoing to the terminal, so we can't see it. Piping in a few newline characters allows the process to continue rather than hanging.
I suspect there is a cleaner way to do this but, for now, this is all I've got:
#!/bin/bash # ...snip... PATHOGEN=`echo "\n\n\n\n\n" | vim -c ':exec ":silent !echo ".exists("g:loaded_pathogen") | exec ":q!"' 2>/dev/null` PATHOGEN=`echo $PATHOGEN | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b` if [[ $PATHOGEN == "1" ]] ; then # found it fi
Comments[]
Better yet use:
vim -nNes -i NONE -u NORC -U NONE <<-"script-delimiter" if exists("g:loaded_vimballPlugin") verbose echo g:loaded_vimballPlugin . "\n" endif script-delimiter echo $?
This will either print g:loaded_vimballPlugin value or not, than will print the command exit code.
What about using the --remote-expr
command-line argument?