浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Steven Occhipinti: Can't open file for writing

Can't open file for writing

E212: Can't open file for writing

Press ENTER or type command to continue

If you use vim, you have probably come across this error before.

It normally happens when you don't have permission to write to your chosen destination.



The temporary solution has traditionally been to save your changes to somewhere where you do have permissions (such as /tmp or ~), then use sudo to cp it across, or re-open the file in vim with sudo.



A collegue at work showed me a great trick to get around this when it happens (Thanks Rich). All you have to do is add this to your .vimrc file:

 command! W w !sudo tee % > /dev/null

Then when you come across this error again, instead of of using :w you can use :W and it will prompt you for your sudo password before saving.

Works brilliantly!

posted on 2012-02-25 12:04  lexus  阅读(2122)  评论(0编辑  收藏  举报