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

前端 未结 7 1969
时光取名叫无心
时光取名叫无心 2020-11-28 01:09

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

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

Also, thes

相关标签:
7条回答
  • 2020-11-28 01:35

    Put this in your .vimrc configuration file.

    set nobackup
    
    0 讨论(0)
  • 2020-11-28 01:38

    On Windows add following lines to _vimrc

    " store backup, undo, and swap files in temp directory
    set directory=$HOME/temp//
    set backupdir=$HOME/temp//
    set undodir=$HOME/temp//
    
    0 讨论(0)
  • 2020-11-28 01:41

    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
    
    0 讨论(0)
  • 2020-11-28 01:45

    I have this setup in my Ubuntu .vimrc. I don't see any swap files in my project files.

    set undofile
    set undolevels=1000         " How many undos
    set undoreload=10000        " number of lines to save for undo
    
    set backup                        " enable backups
    set swapfile                      " enable swaps
    set undodir=$HOME/.vim/tmp/undo     " undo files
    set backupdir=$HOME/.vim/tmp/backup " backups
    set directory=$HOME/.vim/tmp/swap   " swap files
    
    " Make those folders automatically if they don't already exist.
    if !isdirectory(expand(&undodir))
        call mkdir(expand(&undodir), "p")
    endif
    if !isdirectory(expand(&backupdir))
        call mkdir(expand(&backupdir), "p")
    endif
    if !isdirectory(expand(&directory))
        call mkdir(expand(&directory), "p")
    endif
    
    0 讨论(0)
  • 2020-11-28 01:55

    This answer applies to using gVim on Windows 10. I cannot guarantee the same results for other operating systems.

    Add:

    set nobackup
    set noswapfile
    set noundofile
    

    To your _vimrc file.

    Note: This is the direct answer to the question (for Windows 10) and probably not the safest thing to do (read the other answers), but this is the fastest solution in my case.

    0 讨论(0)
  • 2020-11-28 01:56

    ; For Windows Users to back to temp directory

    set backup
    set backupdir=C:\WINDOWS\Temp
    set backupskip=C:\WINDOWS\Temp\*
    set directory=C:\WINDOWS\Temp
    set writebackup
    
    0 讨论(0)
提交回复
热议问题