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