有没有办法禁用vim的交换文件警告?

时间:2016-11-15 22:38:30

标签: git vim

每当我跑

git commit --amend

我认为其他一些命令也是

在编辑提交消息之前,我收到了来自vim的警告,其中包含:

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

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

4 个答案:

答案 0 :(得分:4)

删除交换文件会消除警告:

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

答案 1 :(得分:1)

如果您使用vim / gvim编辑器编辑文件,请在.vimrc / .gvimrc文件中设置以下命令以避免生成交换文件

set noswapfile

答案 2 :(得分:1)

将此添加到您的.vimrc

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

再也不用担心烦人的交换文件了!

答案 3 :(得分:0)

当Vim发生时,您也可以从Vim内的提示中删除有问题的交换文件。你会看到这样的事情:

.single-product .entry-content

如果您在此处点击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

将按顺序尝试使用这些目录。这有助于将交换文件保存在一个位置,因此如果Vim在打开一堆文件时崩溃,则一次删除它们会更容易:

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

它还可以防止交换文件在您的Git树中结束,而不必担心rm ~/.vim/tmp/*