My previous answer was getting a bit crowded and was incomplete (and had only one edit-itteration left). So here is an amended answer which includes both ideas... options and detaching.
As I've mentioned in a follow-up commen to Giles comment (previous answer), the -i option is definitely needed in some situations (on the test Ubuntu system).. so -i and -o are used here.
Because 'gvim' detaches from the script's process, it doesn't wait, and the next command is executed immediately. (Paul Tomblin has already pointed thos out in hes answer).
You can't use bash's wait command, as it only works for child processes. As workaround, you can set up a loop which waits for the non-child process to terminate. This works for an editor which starts with a new process each time (as 'gvim' does in this case).
Here is the modified script
xsel -o >/tmp/xselection
gvim /tmp/xselection 2>/dev/null
pid=$(pgrep -n "gvim") # get gvim's pid and wait
while kill -0 "$pid" 2>/dev/null; do sleep 0.5; done
xsel -i </tmp/xselection
The above assumes that gvim` pid is already established by the time control is passed back to the script. If, under a high system load, the pid hasn't been established upon executing the next command, then this method of waiting for gvim should work.
xsel -o >/tmp/xselection
pre=$(pgrep -n gvim) # get previous gvim pid
gvim /tmp/xselection 2>/dev/null
while pid=$(pgrep -n "gvim"); [[ "$pid" == "$pre" ]]; do sleep .1; done
while kill -0 "$pid" 2>/dev/null; do sleep 0.5; done
xsel -i </tmp/xselection