Find the answer to your Linux question:
Results 1 to 2 of 2
I am trying to configure vim so that when I write a new script it will automatically set the executable bit on it when I write to it for the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    85

    how do I configure vim to set the executable bit on scripts?


    I am trying to configure vim so that when I write a new script it will automatically set the executable bit on it when I write to it for the first time without the annoying
    Code:
    W16: Warning: Mode of file "b.sh" has changed since editing started
    See ":help W16" for more info.
    [O]K, (L)oad File:
    No matter what I do though, it doesn't seem to work.

    here is my .vimrc:

    Code:
    so ~/.vim/mod.vim
    
    autocmd BufNewFile * let fname=expand("%:p")
    autocmd BufNewFile *.pl execute "autocmd BufWritePost ".fname." call SetExecutableBit()" 
    autocmd BufNewFile *.sh execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
    autocmd BufNewFile *.rb execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
    autocmd BufNewFile *.py execute "autocmd BufWritePost ".fname." call SetExecutableBit()"
    and this is my .vim/mod.vim file:
    Code:
    function! SetExecutableBit()
    	let fname=expand("%:p")
    	execute "autocmd FileChangedShell ".fname 
    	execute "!chmod a+x ".fname
    	execute "autocmd! FileChangedShell ".fname
    endfunction

  2. #2
    Just Joined! rm-rf's Avatar
    Join Date
    Mar 2011
    Posts
    85
    nevermind I figured it out. it turns out I have to change it from "BufWritePost" to "BufWrite"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •