How to prevent vim from creating (and leaving) temporary files?

Why does vim create <filename>~ files? Is there a way to disable that?

If it's for backup (or something), I use git for that.

Also, these .<filename.with.path.hints>.swp files too.

How do I tell vim not to create those, or at the least to cleanup after itself?

EDIT

whoops, duplicate:

Why does Vim save files with a ~ extension?

I adopted rogeriopvl's answer from there.

verbatim copy:

set nobackup       "no backup files
set nowritebackup  "only in case you don't want a backup file while editing
set noswapfile     "no swap files

I'd strongly recommend to keep working with swap files (in case Vim crashes).

You can set the directory where the swap files are stored, so they don't clutter your normal directories:

set swapfile
set dir=~/tmp

See also

:help swap-file

把它放在你的.vimrc配置文件中。

set nobackup

; For Windows Users to back to temp directory

set backup
set backupdir=C:WINDOWSTemp
set backupskip=C:WINDOWSTemp*
set directory=C:WINDOWSTemp
set writebackup
链接地址: http://www.djcxy.com/p/41676.html

上一篇: git rebase,跟踪“本地”和“远程”

下一篇: 如何防止vim创建(和离开)临时文件?