Last Updated: September 09, 2019
·
749
· edouard-lopez

Faster and Smarter Editing with `e`

As a Linux/Mac user you have already edited file using the command line editor (e.g. vim, nano, emacs, etc.). And you repeat this tens to hundreds times a day. So what the problem ?

When you attempt to complete this task, your goal to is clear (edit a file), but the way to it is full of traps :

  1. do you have enough privileges ? → cognitive load
  2. did you do any typing error invoking the command ? → friction
  3. do you have your preferred editor installed on this machine ? → cognitive load

Wät ?

Understanding all this and the KISS principle, I give you the shortest command to edit a file:

e /path/to/file   # simplify file editing

Being one-character long come with the additional benefices of:

  • super-easy to remember, no cognitive overload, just edit.
  • reducing typing errors from 50% to 80% :
  • and increasing editing speed by a factor 2 to 5 ;
  • removing privileges issue by invoking editor with adequate privileges ;
    • so you never again edit a file to finally realize that you didn't have enough privileges.

Witchcraft! Shut up and take my money!

No needs my friends. Here is the source:

# @description Edit given file with adequate rights (sudo/user)
# @param    $@|$1  file(s) name
# @return    void
e() {
  if [[ -w "$1" ]]; then
    "$EDITOR" -- "$1"
  else
    sudo -e -- "$1"
  fi
}

Don't like e and prefer to use v ?
No problem, there is room for improvement, feel free to fork and submit pull requests.

More information at Code Mirror: Reduce Frictions and Cognitive Load When Editing Files.