让git忽略vim在所有目录中生成的临时文件的正确方法是什么(无论是跨系统全局的还是单个项目的本地的)?
当前回答
# VIM: Temperory files
*~
# VIM: Swap-files
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# VIM: Commands :cs, :ctags
tags
cscope.*
# VIM session
Session.vim
# VIM: netrw.vim: Network oriented reading, writing, browsing (eg: ftp scp)
.netrwhist
The name of the swap file is normally the same as the file you are editing, with the extension ".swp". On Unix, a '.' is prepended to swap file names in the same directory as the edited file. This avoids that the swap file shows up in a directory listing. On MS-DOS machines and when the 'shortname' option is on, any '.' in the original file name is replaced with '_'. If this file already exists (e.g., when you are recovering from a crash) a warning is given and another extension is used, ".swo", ".swn", etc. An existing file will never be overwritten. The swap file is deleted as soon as Vim stops editing the file. The replacement of '.' with '_' is done to avoid problems with MS-DOS compatible filesystems (e.g., crossdos, multidos).
http://vimdoc.sourceforge.net/htmldoc/recover.html
http://www.vim.org/scripts/script.php?script_id=1075
其他回答
我发现这会让git忽略vim创建的临时文件:
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
*.un~
Session.vim
.netrwhist
*~
也可以在这里观看。
下面是生成交换文件扩展名的实际VIM代码:
/*
* Change the ".swp" extension to find another file that can be used.
* First decrement the last char: ".swo", ".swn", etc.
* If that still isn't enough decrement the last but one char: ".svz"
* Can happen when editing many "No Name" buffers.
*/
if (fname[n - 1] == 'a') /* ".s?a" */
{
if (fname[n - 2] == 'a') /* ".saa": tried enough, give up */
{
EMSG(_("E326: Too many swap files found"));
vim_free(fname);
fname = NULL;
break;
}
--fname[n - 2]; /* ".svz", ".suz", etc. */
fname[n - 1] = 'z' + 1;
}
--fname[n - 1]; /* ".swo", ".swn", etc. */
这将生成如下格式的交换文件:
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
这几乎是包括在github自己的gitignore文件VIM。
正如其他人所正确指出的那样,这个.gitignore也会忽略.svg图像文件和.swf adobe flash文件。
如果您正在使用源代码控制。Vim临时文件非常无用。 因此,您可能希望配置vim不创建它们。
只需编辑您的~/。Vimrc并添加这些行:
set nobackup
set noswapfile
我还建议忽略以下文件:
.*.swp
.*.swo
因为您可能有以.swp结尾的文件
在“git commit”之前退出vim。
要使vim使用其他文件夹作为备份文件(例如/tmp):
set bdir-=.
set bdir+=/tmp
要使vim停止使用当前文件夹的。swp文件:
set dir-=.
set dir+=/tmp
使用-=,+=通常会很好,因为vim对bdir, dir有其他默认值,我们不想全部清除。查看vim帮助以获得更多关于bdir, dir的信息:
:h bdir
:h dir
推荐文章
- 当我试图推到原点时,为什么Git告诉我“没有这样的远程‘原点’”?
- 如何从远程分支中挑选?
- 如何查看一个分支中的哪些提交不在另一个分支中?
- 如何取消在github上的拉请求?
- HEAD和master的区别
- GIT克隆在windows中跨本地文件系统回购
- 强迫自己掌握vi的最好方法是什么?
- RPC失败;卷度传输已关闭,剩余未完成的读取数据
- 我应该在.gitignore文件中添加Django迁移文件吗?
- 错误:您对以下文件的本地更改将被签出覆盖
- Git rebase—即使所有合并冲突都已解决,仍然会继续报错
- 在Git中,我如何知道我的当前版本是什么?
- 如何回到行之前编辑的最后一个在Vim?
- 跟踪所有远程git分支作为本地分支
- 自定义SSH端口上的Git