Disabling swap files creation in vim

后端 未结 10 1332
孤独总比滥情好
孤独总比滥情好 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:22

    Set the following variables in .vimrc or /etc/vimrc to make vim put swap, backup and undo files in a special location instead of the working directory of the file being edited:

    set backupdir=~/.vim/backup//
    set directory=~/.vim/swap//
    set undodir=~/.vim/undo//
    

    Using double trailing slashes in the path tells vim to enable a feature where it avoids name collisions. For example, if you edit a file in one location and another file in another location and both files have the same name, you don't want a name collision to occur in ~/.vim/swap/. If you specify ~/.vim/swap// with two trailing slashes vim will create swap files using the whole path of the files being edited to avoid collisions (slashes in the file's path will be replaced by percent symbol %).

    For example, if you edit /path/one/foobar.txt and /path/two/foobar.txt, then you will see two swap files in ~/.vim/swap/ that are named %path%one%foobar.txt and %path%two%foobar.txt, respectively.

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

    If you are using git, you can add *.swp to .gitignore.

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

    For anyone trying to set this for Rails projects, add

    set directory=tmp,/tmp
    

    into your

    ~/.vimrc
    

    So the .swp files will be in their natural location - the tmp directory (per project).

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

    here are my personal ~/.vimrc backup settings

    " backup to ~/.tmp 
    set backup 
    set backupdir=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp 
    set backupskip=/tmp/*,/private/tmp/* 
    set directory=~/.vim-tmp,~/.tmp,~/tmp,/var/tmp,/tmp 
    set writebackup
    
    0 讨论(0)
提交回复
热议问题