2016-11-15 98 views
1

每当我跑有没有办法禁用vim的交换文件警告?

git commit --amend 

,我认为其他一些命令也

我从VIM警告之前我编辑提交信息,说像:

E325: ATTENTION 
Found a swap file by the name "~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp" 

我总是忽略警告,然后写我的提交信息并保存文件。有没有办法可以永久禁用此警告?

+3

只需删除交换文件... –

+3

删除交换文件将停止警告提示。 –

+0

啊谢谢!没有意识到这是事实,问题解决了:) – maxfowler

回答

3

删除交换文件摆脱了警告:

rm ~/Desktop/code/web/.git/.COMMIT_EDITMSG.swp 
1

如果您正在编辑用vim/gvim的编辑器中的文件,那么在你的.vimrc/.gvimrc里文件,以避免产生设置以下命令交换文件

set noswapfile 
0

添加到您的.vimrc

" Don't let Vim's "Found a swap file" message block input 
set shortmess=A 

而且从来w ^再次讨厌烦人的交换文件消息!

0

您也可以在Vim中的提示符中删除违规的交换文件。你会看到这样的事情:

E325: ATTENTION 
Found a swap file by the name "~/.vim/tmp/test.txt.swp" 
      owned by: jim dated: Mon Nov 21 00:54:03 2016 
     [cannot be read] 
While opening file "test.txt" 
      dated: Mon Nov 21 00:53:38 2016 

(1) Another program may be editing the same file. If this is the case, 
    be careful not to end up with two different instances of the same 
    file when making changes. Quit, or continue with caution. 
(2) An edit session for this file crashed. 
    If this is the case, use ":recover" or "vim -r test.txt" 
    to recover the changes (see ":help recovery"). 
    If you did this already, delete the swap file "/Users/jim/.vim/tmp/test.txt.swp" 
    to avoid this message. 

Swap file "~/.vim/tmp/test.txt.swp" already exists! 
[O]pen Read-Only, (E)dit anyway, (R)ecover, (D)elete it, (Q)uit, (A)bort: 

如果你打D在这里,它会删除导致错误信息的交换文件,您将不会再看到它是一个文件。然后您可以再次编写文件,并且不会出现错误。

与您的问题没有直接关系,但您可能要考虑的是更改directory选项,以便交换文件不会与您正在编辑的文件在同一目录中创建。我用:

set directory=~/.vim/tmp,/var/tmp,/tmp 

这将尝试使用这些目录,按顺序。这有助于保持交换文件在同一个地方,所以它更容易将它们全部删除一次,如果Vim的崩溃,当你有一大堆文件的打开:

rm ~/.vim/tmp/* 

它还可以防止交换文件在你自己的Git树结束了,而不用担心.gitignore

相关问题