vi is failed with error "E382: Cannot write, 'buftype' option is set" in Linux

在linux下生成jar文件遇到了编码问题,于是想vi t.jar,在保存是报错:E382: Cannot write, 'buftype' option is set

解决方法:

可以用下面的命名查看buftype的设置,当buftype=nofile时,不能保存文件,只有当buftype=空时,才可以保存

>> vi t.jar

>> :verbose set buftype

在文件的最下方可以看到

  buftype=nofile

    Last set from /usr/share/vim/vim74/autoload/zip.vim

  Press ENTER or type command to continue

修改buftype的方法:

>> vi t.jar

>> :setlocal buftype=

>> :verbose set buftype

在文件的最下方可以看到

  buftype=

然后就可以修改想要修改的内容,然后保存了

比如

>> :set fileencoding=latin1

>> :wq!

这样就会修改成功

如果想在保存前改回原设置,可用下面的命令:

>> :setlocal buftype=nofile

默认保存完,也是改回了nofile