Disabling swap files creation in vim

后端 未结 10 1331
孤独总比滥情好
孤独总比滥情好 2020-12-12 09:06

Is there a way to disable .swp files creation in vim? or at least create them all in one place so I can find and delete them easily.

I find them especia

相关标签:
10条回答
  • 2020-12-12 09:15

    You can set backupdir and directory to null in order to completely disable your swap files, but it is generally recommended to simply put them in a centralized directory. Vim takes care of making sure that there aren't name collissions or anything like that; so, this is a completely safe alternative:

    set backupdir=~/.vim/backup/
    set directory=~/.vim/backup/
    
    0 讨论(0)
  • 2020-12-12 09:16

    If you put set directory="" in your exrc file, you will turn off the swap file. However, doing so will disable recovery.

    More info here.

    0 讨论(0)
  • 2020-12-12 09:18

    To disable swap files from within vim, type

    :set noswapfile
    

    To disable swap files permanently, add the below to your ~/.vimrc file

    set noswapfile
    

    For more details see the Vim docs on swapfile

    0 讨论(0)
  • 2020-12-12 09:19

    I found the answer here:

    vim -n <file>
    

    opens file without swapfile.

    In addition:

    set dir=/tmp
    

    in .vimrc creates the swapfiles in /tmp.

    0 讨论(0)
  • 2020-12-12 09:19

    create no vim swap file just for a particular file

    autocmd bufenter  c:/aaa/Dropbox/TapNote/Todo.txt :set noswapfile
    
    0 讨论(0)
  • 2020-12-12 09:20

    I agree with those who question why vim needs all this 'disaster recovery' stuff when no other text editors bother with it. I don't want vim creating ANY extra files in the edited file's directory when I'm editing it, thank you very much. To that end, I have this in my _vimrc to disable swap files, and move irritating 'backup' files to the Temp dir:

    " Uncomment below to prevent 'tilde backup files' (eg. myfile.txt~) from being created
    "set nobackup
    
    " Uncomment below to cause 'tilde backup files' to be created in a different dir so as not to clutter up the current file's directory (probably a better idea than disabling them altogether)
    set backupdir=C:\Windows\Temp
    
    " Uncomment below to disable 'swap files' (eg. .myfile.txt.swp) from being created
    set noswapfile
    
    0 讨论(0)
提交回复
热议问题