Vim Tips Wiki
Advertisement
Tip 212 Printable Monobook Previous Next

created February 7, 2002 · complexity intermediate · author Max Ischenko · version 6.0


While creating scripts and others executable files with Vim it is needed to set UNIX executable bit on the file.

You can do this from inside Vim with :!chmod a+x %. The % represents current buffer's filename.

The problem is that Vim will notice attribute changes and prompt you to reload a file. If you do this, your undo history for the file will be lost.

The following function facilitate changing executable attributes without reloading a buffer.

fun! SetExecutableBit()
  let fname = expand("%:p")
  :checktime
  exec "au FileChangedShell " . fname . " :echo"
  :silent !chmod a+x %
  :checktime
  exec "au! FileChangedShell " . fname
endfun
command -nargs=0 Xbit call SetExecutableBit()

Now you can type :Xbit to make the file executable.

Comments

Advertisement