I have a few shell scripts where I find files and open them in vim, with the filenames being stored in shell variables that are passed to vim. Since I don't want to start a vim session unless at least one file is found, I find myself checking to see if the variable is empty every time, like so:
... if [ -z "$files" ] ; then echo no files found exit 1 else vim $files fi
I was wondering if it would be possible to eliminate the need for this by having vim quit if the buffer is empty (no lines and the
modified option is not set) using the
-c command line flag to which one can pass a vim command. However I do not think vim can process
if statements from the command line. (I was thinking of something like this:)
vim $files -c "if line('$') == 1 && &modified == 0 then :quitall endif"
I tried to see if there was an autocommand event for this, but couldn't find one. Any thoughts ?