在编辑新文件时自动保存当前缓冲区

时间:2015-12-25 14:48:19

标签: vim

我在当前缓冲区中进行了一些更改,我希望vim在使用以下命令编辑新文件时自动保存当前缓冲区:

:e another_file_which_is_not_a_buffer_in_vim_yet

我在.vimrc文件中添加了以下行,但它没有用。

autocmd BufLeave * update

Vim仍然提示我No write since last change,为什么?我怎样才能使它工作?顺便说一句,我只想保存当前缓冲区而不是所有缓冲区,因为保存所有缓冲区似乎搞乱了缓冲区的顺序,这会在我运行:bp:bn时带来麻烦。

2 个答案:

答案 0 :(得分:5)

除了触发:edit的内容之外,Vim还可以为autowrite保存其他内容:

set autowriteall

相关手册摘录:

autowrite

'autowrite' 'aw'  boolean (default off)
                  global
  Write the contents of the file, if it has been modified, on each
  :next, :rewind, :last, :first, :previous, :stop, :suspend, :tag, :!,
  :make, CTRL-] and CTRL-^ command; and when a :buffer, CTRL-O, CTRL-I,
  '{A-Z0-9}, or `{A-Z0-9} command takes one to another file.
  Note that for some commands the 'autowrite' option is not used, see
  'autowriteall' for that.

autowriteall

'autowriteall' 'awa'  boolean (default off)
                      global
                      {not in Vi}
  Like 'autowrite', but also used for commands ":edit", ":enew", ":quit",
  ":qall", ":exit", ":xit", ":recover" and closing the Vim window.
  Setting this option also implies that Vim behaves like 'autowrite' has
  been set.

答案 1 :(得分:2)

这行代码可以解决问题。将其放在.vimrc文件中。如果您在vim中输入.vimrc,则可以找到此:version文件的位置。

set autowrite

有关此主题的更多信息,请参阅此link