if (( $+commands[sublim] )); then
  export EDITOR='sublime'
elif (( $+commands[nano] )); then
  export EDITOR='nano'
elif (( $+commands[vim] )); then
  export EDITOR='vim'
else
  export EDITOR='vi'
fi

if test $(which sublime)
then
  export EDITOR='sublime'
else
  export EDITOR='nano'
fi

--- 
+++ 
@@ -1,6 +1,9 @@
-if test $(which sublime)
-then
+if (( $+commands[sublim] )); then
   export EDITOR='sublime'
+elif (( $+commands[nano] )); then
+  export EDITOR='nano'
+elif (( $+commands[vim] )); then
+  export EDITOR='vim'
 else
-  export EDITOR='nano'
+  export EDITOR='vi'
 fi
Fix and improve editor selection
