Shellisms: Automagically sudo when editing files

I get irritated to no end when I start editing a file in Vim, only to realize I don’t have write permissions to that file. I wrote this little bash function to address that a few years ago. It checks if I have write permissions to the file I am trying to open, and runs the editor in sudo if I do not. It could be cleaner, but it works. Simply toss it into your .bashrc, and enjoy.
Continue reading “Shellisms: Automagically sudo when editing files”

Shellisms: Automagically sudo when editing files

Shellisms: Quickly edit any executable in your $PATH

I often find my self taking a look into the guts of commands I am executing. Instead of taking time digging around for the path, I wrote this little bash function to save me some time:

complete -c vipath # Auto-completes any executables in my $PATH
vipath () {
  FILE=`which $1`
  /usr/bin/env editor $FILE
}

Toss the above in your .bashrc, and you’re off.

vipath update-rc.d # Result: Open /usr/sbin/update-rc.d in your editor
Shellisms: Quickly edit any executable in your $PATH

Quick Vim tip: Change the way ‘change’ works

By default in Vim, when you begin to :change a word or a line, the old string which you were changing is immediately cleared from the buffer. This behaviour is different from classic vi, where you can still view the old string while you overwrite it. I prefer the old vi behaviour, and this can be set in Vim using the following command:

:set cpoptions=$

This stupid setting took me forever to find in the docs, as I wasn’t sure quite how to search for it. A diamond-plated internet goes to the first person that can form a generic Google search that will pull this info up.

Quick Vim tip: Change the way ‘change’ works