Why does Vim save files with a ~ extension?











up vote
160
down vote

favorite
72












I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.



I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?










share|improve this question
























  • Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
    – dirkgently
    Mar 3 '09 at 18:00






  • 1




    dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
    – Ross
    Mar 3 '09 at 18:02















up vote
160
down vote

favorite
72












I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.



I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?










share|improve this question
























  • Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
    – dirkgently
    Mar 3 '09 at 18:00






  • 1




    dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
    – Ross
    Mar 3 '09 at 18:02













up vote
160
down vote

favorite
72









up vote
160
down vote

favorite
72






72





I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.



I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?










share|improve this question















I've found that while using Vim on Windows Vim saves the file, a .ext.swp file that's deleted on closing the Vim window and a .ext~ file.



I assume the .ext.swp file is a session backup in case Vim crashes. What's the purpose of the .ext~ file however? Is this a permanent backup file? It's annoying as I'd like to copy all the files I'm working on to my host, without these duplicates. How can I turn this off or, if it's there for a good reason, hide the files?







vim






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 3 '09 at 20:52

























asked Mar 3 '09 at 17:56









Ross

29k33103166




29k33103166












  • Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
    – dirkgently
    Mar 3 '09 at 18:00






  • 1




    dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
    – Ross
    Mar 3 '09 at 18:02


















  • Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
    – dirkgently
    Mar 3 '09 at 18:00






  • 1




    dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
    – Ross
    Mar 3 '09 at 18:02
















Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
– dirkgently
Mar 3 '09 at 18:00




Do you have any file open simultaneously in more than one place, they will create a .ext.swp.
– dirkgently
Mar 3 '09 at 18:00




1




1




dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
– Ross
Mar 3 '09 at 18:02




dirkgently: No, on here I can open a file in the only vim window and it will create the .swp file. I'm not too fussed about that as it's removed when I save/close the window.
– Ross
Mar 3 '09 at 18:02












9 Answers
9






active

oldest

votes

















up vote
205
down vote



accepted










The *.ext~ file is a backup file, containing the file as it was before you edited it.



The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).



To switch off automatic creation of backup files, use (in your vimrc):



set nobackup
set nowritebackup


Where nowritebackup changes the default "save" behavior of Vim, which is:




  1. write buffer to new file

  2. delete the original file

  3. rename the new file


and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.






share|improve this answer



















  • 7




    +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
    – Merlyn Morgan-Graham
    Mar 28 '11 at 22:16






  • 1




    Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
    – Merlyn Morgan-Graham
    Mar 28 '11 at 22:22










  • @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
    – Tomalak
    Mar 28 '11 at 22:26








  • 5




    There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
    – Merlyn Morgan-Graham
    Mar 28 '11 at 22:34








  • 24




    Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
    – tsukimi
    Dec 5 '13 at 1:10


















up vote
199
down vote













I think the better solution is to place these lines in your vimrc file



set backupdir=~/vimtmp,.
set directory=~/vimtmp,.


You have to create a directory in your home directory called vimtmp for this to work.



That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.






share|improve this answer

















  • 19




    +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
    – jonyamo
    Jun 6 '11 at 19:01






  • 10




    Why do you need ,. at the end of each line?
    – shin
    Jan 30 '14 at 1:07






  • 7




    @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
    – xixixao
    Jan 30 '14 at 21:58






  • 2




    @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
    – Score_Under
    Aug 20 '14 at 2:31






  • 11




    Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
    – Hacknightly
    Jun 12 '16 at 17:58


















up vote
23
down vote













To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):



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





share|improve this answer






























    up vote
    12
    down vote













    :set nobackup 


    will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.



    You find more information on backups under :he backup.






    share|improve this answer




























      up vote
      11
      down vote













      And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:



      au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'


      This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).






      share|improve this answer



















      • 3




        you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
        – rampion
        Mar 3 '09 at 22:30






      • 1




        The vim help fully describes this technique. See :help backupext
        – netjeff
        Jun 9 '11 at 19:05




















      up vote
      6
      down vote













      You're correct that the .swp file is used by vim for locking and as a recovery file.



      Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...






      share|improve this answer





















      • +1 for mentioning the purpose as a lock file. I didn't think of that.
        – Tomalak
        Mar 3 '09 at 18:36


















      up vote
      5
      down vote













      Put this line into your vimrc:



      set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile


      In Windows that would be the C:Program Files (x86)vim_vimrc file for system-wide vim configuration for all users.



      Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.





      I wish Vim had that line included by default. Nobody likes ugly directories.



      Let the user choose if and how she wants to enable advanced backup/undo file features first.



      This is the most annoying part of Vim.



      The next step is to set up set noeb vb t_vb= to disable beeping :P






      share|improve this answer




























        up vote
        4
        down vote













        The only option that worked for me was to put this line in my ~/.vimrc file



        set noundofile



        The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)






        share|improve this answer




























          up vote
          0
          down vote













          I had to add set noundofile to ~_gvimrc



          The "~" directory can be identified by changing the directory with the cd ~ command






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














             

            draft saved


            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f607435%2fwhy-does-vim-save-files-with-a-extension%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            9 Answers
            9






            active

            oldest

            votes








            9 Answers
            9






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            205
            down vote



            accepted










            The *.ext~ file is a backup file, containing the file as it was before you edited it.



            The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).



            To switch off automatic creation of backup files, use (in your vimrc):



            set nobackup
            set nowritebackup


            Where nowritebackup changes the default "save" behavior of Vim, which is:




            1. write buffer to new file

            2. delete the original file

            3. rename the new file


            and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.






            share|improve this answer



















            • 7




              +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:16






            • 1




              Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:22










            • @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
              – Tomalak
              Mar 28 '11 at 22:26








            • 5




              There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:34








            • 24




              Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
              – tsukimi
              Dec 5 '13 at 1:10















            up vote
            205
            down vote



            accepted










            The *.ext~ file is a backup file, containing the file as it was before you edited it.



            The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).



            To switch off automatic creation of backup files, use (in your vimrc):



            set nobackup
            set nowritebackup


            Where nowritebackup changes the default "save" behavior of Vim, which is:




            1. write buffer to new file

            2. delete the original file

            3. rename the new file


            and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.






            share|improve this answer



















            • 7




              +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:16






            • 1




              Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:22










            • @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
              – Tomalak
              Mar 28 '11 at 22:26








            • 5




              There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:34








            • 24




              Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
              – tsukimi
              Dec 5 '13 at 1:10













            up vote
            205
            down vote



            accepted







            up vote
            205
            down vote



            accepted






            The *.ext~ file is a backup file, containing the file as it was before you edited it.



            The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).



            To switch off automatic creation of backup files, use (in your vimrc):



            set nobackup
            set nowritebackup


            Where nowritebackup changes the default "save" behavior of Vim, which is:




            1. write buffer to new file

            2. delete the original file

            3. rename the new file


            and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.






            share|improve this answer














            The *.ext~ file is a backup file, containing the file as it was before you edited it.



            The *.ext.swp file is the swap file, which serves as a lock file and contains the undo/redo history as well as any other internal info Vim needs. In case of a crash you can re-open your file and Vim will restore its previous state from the swap file (which I find helpful, so I don't switch it off).



            To switch off automatic creation of backup files, use (in your vimrc):



            set nobackup
            set nowritebackup


            Where nowritebackup changes the default "save" behavior of Vim, which is:




            1. write buffer to new file

            2. delete the original file

            3. rename the new file


            and makes Vim write the buffer to the original file (resulting in the risk of destroying it in case of an I/O error). But you prevent "jumping files" on the Windows desktop with it, which is the primary reason for me to have nowritebackup in place.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 28 '11 at 22:24

























            answered Mar 3 '09 at 18:04









            Tomalak

            254k51422538




            254k51422538








            • 7




              +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:16






            • 1




              Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:22










            • @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
              – Tomalak
              Mar 28 '11 at 22:26








            • 5




              There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:34








            • 24




              Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
              – tsukimi
              Dec 5 '13 at 1:10














            • 7




              +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:16






            • 1




              Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:22










            • @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
              – Tomalak
              Mar 28 '11 at 22:26








            • 5




              There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
              – Merlyn Morgan-Graham
              Mar 28 '11 at 22:34








            • 24




              Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
              – tsukimi
              Dec 5 '13 at 1:10








            7




            7




            +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:16




            +1 For you prevent "jumping files" on the Windows desktop. Googled and found this answer
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:16




            1




            1




            Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:22




            Actually - do I have to have both nobackup and nowritebackup? Is there a way to write a copy of the file as a backup, but not do this write/delete/rename stuff?
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:22












            @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
            – Tomalak
            Mar 28 '11 at 22:26






            @Merlyn: If you have backup (as opposed to nobackup), then Vim will create a backup (the *.ext~ file). This is completely unrelated to nowritebackup.
            – Tomalak
            Mar 28 '11 at 22:26






            5




            5




            There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:34






            There is a table describing different behavior between combination of those switches: help backup-table. It turns out setting neither nobackup nor nowritebackup, but instead setting backupcopy=yes also solves the "jumping" problem. This may hurt perf, though, so to each their own
            – Merlyn Morgan-Graham
            Mar 28 '11 at 22:34






            24




            24




            Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
            – tsukimi
            Dec 5 '13 at 1:10




            Instead of turning off , backup to a directory set backupdir=~/.vim/backup in .vimrc or _vimrc on windows
            – tsukimi
            Dec 5 '13 at 1:10












            up vote
            199
            down vote













            I think the better solution is to place these lines in your vimrc file



            set backupdir=~/vimtmp,.
            set directory=~/vimtmp,.


            You have to create a directory in your home directory called vimtmp for this to work.



            That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.






            share|improve this answer

















            • 19




              +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
              – jonyamo
              Jun 6 '11 at 19:01






            • 10




              Why do you need ,. at the end of each line?
              – shin
              Jan 30 '14 at 1:07






            • 7




              @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
              – xixixao
              Jan 30 '14 at 21:58






            • 2




              @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
              – Score_Under
              Aug 20 '14 at 2:31






            • 11




              Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
              – Hacknightly
              Jun 12 '16 at 17:58















            up vote
            199
            down vote













            I think the better solution is to place these lines in your vimrc file



            set backupdir=~/vimtmp,.
            set directory=~/vimtmp,.


            You have to create a directory in your home directory called vimtmp for this to work.



            That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.






            share|improve this answer

















            • 19




              +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
              – jonyamo
              Jun 6 '11 at 19:01






            • 10




              Why do you need ,. at the end of each line?
              – shin
              Jan 30 '14 at 1:07






            • 7




              @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
              – xixixao
              Jan 30 '14 at 21:58






            • 2




              @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
              – Score_Under
              Aug 20 '14 at 2:31






            • 11




              Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
              – Hacknightly
              Jun 12 '16 at 17:58













            up vote
            199
            down vote










            up vote
            199
            down vote









            I think the better solution is to place these lines in your vimrc file



            set backupdir=~/vimtmp,.
            set directory=~/vimtmp,.


            You have to create a directory in your home directory called vimtmp for this to work.



            That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.






            share|improve this answer












            I think the better solution is to place these lines in your vimrc file



            set backupdir=~/vimtmp,.
            set directory=~/vimtmp,.


            You have to create a directory in your home directory called vimtmp for this to work.



            That way you get the benefit of both worlds, you don't have to see the files, but if something does get futzed you can go get your backup file from vimtmp. Don't forget to clean the directory out every now and then.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Oct 26 '09 at 16:44









            user183135

            2,2302147




            2,2302147








            • 19




              +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
              – jonyamo
              Jun 6 '11 at 19:01






            • 10




              Why do you need ,. at the end of each line?
              – shin
              Jan 30 '14 at 1:07






            • 7




              @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
              – xixixao
              Jan 30 '14 at 21:58






            • 2




              @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
              – Score_Under
              Aug 20 '14 at 2:31






            • 11




              Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
              – Hacknightly
              Jun 12 '16 at 17:58














            • 19




              +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
              – jonyamo
              Jun 6 '11 at 19:01






            • 10




              Why do you need ,. at the end of each line?
              – shin
              Jan 30 '14 at 1:07






            • 7




              @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
              – xixixao
              Jan 30 '14 at 21:58






            • 2




              @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
              – Score_Under
              Aug 20 '14 at 2:31






            • 11




              Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
              – Hacknightly
              Jun 12 '16 at 17:58








            19




            19




            +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
            – jonyamo
            Jun 6 '11 at 19:01




            +1 I actually have mine set to ~/.vim/tmp, but either way, this has saved my ass on more than one occasion.
            – jonyamo
            Jun 6 '11 at 19:01




            10




            10




            Why do you need ,. at the end of each line?
            – shin
            Jan 30 '14 at 1:07




            Why do you need ,. at the end of each line?
            – shin
            Jan 30 '14 at 1:07




            7




            7




            @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
            – xixixao
            Jan 30 '14 at 21:58




            @shin Vim will use the first available dir, so in this case if ~/vimtmp doesn't exist it will use the current working directory
            – xixixao
            Jan 30 '14 at 21:58




            2




            2




            @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
            – Score_Under
            Aug 20 '14 at 2:31




            @SalmanPK In an ideal world you should not be editing configuration files directly on publicly accessible servers
            – Score_Under
            Aug 20 '14 at 2:31




            11




            11




            Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
            – Hacknightly
            Jun 12 '16 at 17:58




            Use two slashes at the end of the path. For instance, set backupdir=~/.vim/.backup// - the "//" at the end of the directory means that file names will be built from the complete path to the file with all path separators substituted to percent "%" sign. This will ensure file name uniqueness in the preserve directory.
            – Hacknightly
            Jun 12 '16 at 17:58










            up vote
            23
            down vote













            To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):



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





            share|improve this answer



























              up vote
              23
              down vote













              To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):



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





              share|improve this answer

























                up vote
                23
                down vote










                up vote
                23
                down vote









                To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):



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





                share|improve this answer














                To turn off those files, just add these lines to .vimrc (vim configuration file on unix based OS):



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






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Mar 3 '09 at 18:14

























                answered Mar 3 '09 at 18:04









                rogeriopvl

                27k74557




                27k74557






















                    up vote
                    12
                    down vote













                    :set nobackup 


                    will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.



                    You find more information on backups under :he backup.






                    share|improve this answer

























                      up vote
                      12
                      down vote













                      :set nobackup 


                      will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.



                      You find more information on backups under :he backup.






                      share|improve this answer























                        up vote
                        12
                        down vote










                        up vote
                        12
                        down vote









                        :set nobackup 


                        will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.



                        You find more information on backups under :he backup.






                        share|improve this answer












                        :set nobackup 


                        will turn off backups. You can also set a backupdir if you still want those backup files but in a central folder. This way your working dir is not littered with ~ files.



                        You find more information on backups under :he backup.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 3 '09 at 18:02









                        f3lix

                        23.6k95578




                        23.6k95578






















                            up vote
                            11
                            down vote













                            And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:



                            au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'


                            This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).






                            share|improve this answer



















                            • 3




                              you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                              – rampion
                              Mar 3 '09 at 22:30






                            • 1




                              The vim help fully describes this technique. See :help backupext
                              – netjeff
                              Jun 9 '11 at 19:05

















                            up vote
                            11
                            down vote













                            And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:



                            au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'


                            This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).






                            share|improve this answer



















                            • 3




                              you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                              – rampion
                              Mar 3 '09 at 22:30






                            • 1




                              The vim help fully describes this technique. See :help backupext
                              – netjeff
                              Jun 9 '11 at 19:05















                            up vote
                            11
                            down vote










                            up vote
                            11
                            down vote









                            And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:



                            au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'


                            This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).






                            share|improve this answer














                            And you can also set a different backup extension and where to save those backup (I prefer ~/.vimbackups on linux). I used to use "versioned" backups, via:



                            au BufWritePre * let &bex = '-' . strftime("%Y%m%d-%H%M%S") . '.vimbackup'


                            This sets a dynamic backup extension (ORIGINALFILENAME-YYYYMMDD-HHMMSS.vimbackup).







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 6 '12 at 7:11

























                            answered Mar 3 '09 at 22:13









                            Zsolt Botykai

                            37.9k107196




                            37.9k107196








                            • 3




                              you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                              – rampion
                              Mar 3 '09 at 22:30






                            • 1




                              The vim help fully describes this technique. See :help backupext
                              – netjeff
                              Jun 9 '11 at 19:05
















                            • 3




                              you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                              – rampion
                              Mar 3 '09 at 22:30






                            • 1




                              The vim help fully describes this technique. See :help backupext
                              – netjeff
                              Jun 9 '11 at 19:05










                            3




                            3




                            you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                            – rampion
                            Mar 3 '09 at 22:30




                            you might want to include how to set up the back up directory, i.e. putting set backupdir=~/.vimbackups in your ~/.vimrc
                            – rampion
                            Mar 3 '09 at 22:30




                            1




                            1




                            The vim help fully describes this technique. See :help backupext
                            – netjeff
                            Jun 9 '11 at 19:05






                            The vim help fully describes this technique. See :help backupext
                            – netjeff
                            Jun 9 '11 at 19:05












                            up vote
                            6
                            down vote













                            You're correct that the .swp file is used by vim for locking and as a recovery file.



                            Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...






                            share|improve this answer





















                            • +1 for mentioning the purpose as a lock file. I didn't think of that.
                              – Tomalak
                              Mar 3 '09 at 18:36















                            up vote
                            6
                            down vote













                            You're correct that the .swp file is used by vim for locking and as a recovery file.



                            Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...






                            share|improve this answer





















                            • +1 for mentioning the purpose as a lock file. I didn't think of that.
                              – Tomalak
                              Mar 3 '09 at 18:36













                            up vote
                            6
                            down vote










                            up vote
                            6
                            down vote









                            You're correct that the .swp file is used by vim for locking and as a recovery file.



                            Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...






                            share|improve this answer












                            You're correct that the .swp file is used by vim for locking and as a recovery file.



                            Try putting set nobackup in your vimrc if you don't want these files. See the Vim docs for various backup related options if you want the whole scoop, or want to have .bak files instead...







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Mar 3 '09 at 18:03









                            dwc

                            18.3k53651




                            18.3k53651












                            • +1 for mentioning the purpose as a lock file. I didn't think of that.
                              – Tomalak
                              Mar 3 '09 at 18:36


















                            • +1 for mentioning the purpose as a lock file. I didn't think of that.
                              – Tomalak
                              Mar 3 '09 at 18:36
















                            +1 for mentioning the purpose as a lock file. I didn't think of that.
                            – Tomalak
                            Mar 3 '09 at 18:36




                            +1 for mentioning the purpose as a lock file. I didn't think of that.
                            – Tomalak
                            Mar 3 '09 at 18:36










                            up vote
                            5
                            down vote













                            Put this line into your vimrc:



                            set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile


                            In Windows that would be the C:Program Files (x86)vim_vimrc file for system-wide vim configuration for all users.



                            Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.





                            I wish Vim had that line included by default. Nobody likes ugly directories.



                            Let the user choose if and how she wants to enable advanced backup/undo file features first.



                            This is the most annoying part of Vim.



                            The next step is to set up set noeb vb t_vb= to disable beeping :P






                            share|improve this answer

























                              up vote
                              5
                              down vote













                              Put this line into your vimrc:



                              set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile


                              In Windows that would be the C:Program Files (x86)vim_vimrc file for system-wide vim configuration for all users.



                              Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.





                              I wish Vim had that line included by default. Nobody likes ugly directories.



                              Let the user choose if and how she wants to enable advanced backup/undo file features first.



                              This is the most annoying part of Vim.



                              The next step is to set up set noeb vb t_vb= to disable beeping :P






                              share|improve this answer























                                up vote
                                5
                                down vote










                                up vote
                                5
                                down vote









                                Put this line into your vimrc:



                                set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile


                                In Windows that would be the C:Program Files (x86)vim_vimrc file for system-wide vim configuration for all users.



                                Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.





                                I wish Vim had that line included by default. Nobody likes ugly directories.



                                Let the user choose if and how she wants to enable advanced backup/undo file features first.



                                This is the most annoying part of Vim.



                                The next step is to set up set noeb vb t_vb= to disable beeping :P






                                share|improve this answer












                                Put this line into your vimrc:



                                set nobk nowb noswf noudf " nobackup nowritebackup noswapfile noundofile


                                In Windows that would be the C:Program Files (x86)vim_vimrc file for system-wide vim configuration for all users.



                                Setting the last one noundofile is important in Windows to prevent the creation of *~ tilda files after editing.





                                I wish Vim had that line included by default. Nobody likes ugly directories.



                                Let the user choose if and how she wants to enable advanced backup/undo file features first.



                                This is the most annoying part of Vim.



                                The next step is to set up set noeb vb t_vb= to disable beeping :P







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 10 '17 at 2:34









                                w17t

                                6821017




                                6821017






















                                    up vote
                                    4
                                    down vote













                                    The only option that worked for me was to put this line in my ~/.vimrc file



                                    set noundofile



                                    The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)






                                    share|improve this answer

























                                      up vote
                                      4
                                      down vote













                                      The only option that worked for me was to put this line in my ~/.vimrc file



                                      set noundofile



                                      The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)






                                      share|improve this answer























                                        up vote
                                        4
                                        down vote










                                        up vote
                                        4
                                        down vote









                                        The only option that worked for me was to put this line in my ~/.vimrc file



                                        set noundofile



                                        The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)






                                        share|improve this answer












                                        The only option that worked for me was to put this line in my ~/.vimrc file



                                        set noundofile



                                        The other options referring to backup files did not prevent the creation of the temp files ending in ~ (tilde)







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Apr 6 '17 at 15:18









                                        Logan

                                        412




                                        412






















                                            up vote
                                            0
                                            down vote













                                            I had to add set noundofile to ~_gvimrc



                                            The "~" directory can be identified by changing the directory with the cd ~ command






                                            share|improve this answer

























                                              up vote
                                              0
                                              down vote













                                              I had to add set noundofile to ~_gvimrc



                                              The "~" directory can be identified by changing the directory with the cd ~ command






                                              share|improve this answer























                                                up vote
                                                0
                                                down vote










                                                up vote
                                                0
                                                down vote









                                                I had to add set noundofile to ~_gvimrc



                                                The "~" directory can be identified by changing the directory with the cd ~ command






                                                share|improve this answer












                                                I had to add set noundofile to ~_gvimrc



                                                The "~" directory can be identified by changing the directory with the cd ~ command







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Mar 1 at 19:44









                                                Josh

                                                90811014




                                                90811014






























                                                     

                                                    draft saved


                                                    draft discarded



















































                                                     


                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f607435%2fwhy-does-vim-save-files-with-a-extension%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    Feedback on college project

                                                    Futebolista

                                                    Albești (Vaslui)