git ignore vim temporary files

后端 未结 12 925
刺人心
刺人心 2020-12-12 08:38

What is the correct way to make git ignore temporary files produced by vim in all directories (either globally across the system or locally for a single project)?

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

    I would also recommend to think to ignore files like:

    .*.swp
    .*.swo
    

    as you may have files that end with .swp

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

    Alternatively you can configure vim to save the swapfiles to a separate location, e.g. by adding lines similar to the following to your .vimrc file:

    set backupdir=$TEMP//
    set directory=$TEMP//
    

    See this vim tip for more info.

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

    Quit vim before "git commit".

    to make vim use other folders for backup files, (/tmp for example):

    set bdir-=.
    set bdir+=/tmp
    

    to make vim stop using current folder for .swp files:

    set dir-=.
    set dir+=/tmp
    

    Use -=, += would be generally good, because vim has other defaults for bdir, dir, we don't want to clear all. Check vim help for more about bdir, dir:

    :h bdir
    :h dir
    
    0 讨论(0)
  • 2020-12-12 09:24

    sure,

    just have to create a ".gitignore" on the home directory of your project and have to contain

    *.swp
    

    that's it

    in one command

    project-home-directory$ echo '*.swp' >> .gitignore
    
    0 讨论(0)
  • 2020-12-12 09:25

    Vim temporary files end with ~ so you can add to the file .gitignore the line

    *~
    

    Vim also creates swap files that have the swp and swo extensions. to remove those use the lines:

    *.swp
    *.swo
    

    This will ignore all the vim temporary files in a single project

    If you want to do it globally, you can create a .gitignore file in your home (you can give it other name or location), and use the following command:

    git config --global core.excludesfile ~/.gitignore
    

    Then you just need to add the files you want to ignore to that file

    0 讨论(0)
  • 2020-12-12 09:26
    # 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

    0 讨论(0)
提交回复
热议问题