I've noticed I have some dotfiles that end with .un~
, for example I have a .vividchalk.vim.un~
, but I'm not sure where that came from. It seems like they are created when I use Vim in the Terminal. What are these files? Can have them remove themselves when I close the file I'm editing?

- 167,457
- 16
- 250
- 324

- 4,109
- 6
- 30
- 35
3 Answers
When you edit and save files, Vim creates a file with the same name as the original file and an un~
extension at the end.
Vim 7.3 contains a new feature persistent undo, that is, undo information
won't be lost when quitting Vim and be stored in a file that ends with .un~
.
You have set the undofile
option, so Vim creates an undo file when saving
the original file. You can stop Vim from creating the backup file, by
clearing the option:
:set noundofile
Note that, by default this option is turned off. You have explicitly
enabled the undofile
option in one of the initialization files. If you
want your undofiles to be stored only in a particular directory, you can
point the undodir
option to a directory that will contain all your
aggregated undofiles.
-
6Thanks! I'm new to Vim and trying to understand and configure without cargo culting. I see now that setting is coming from `vim-sensible`. Reading the ReadMe on [vim-sensible](https://github.com/tpope/vim-sensible) is very helpful. And I learned (from a peepcode screencast) that I can do `:verbose set undofile?` and I'll see where that option is set. I think I have that right. – kaplan Mar 27 '13 at 17:24
-
1I have Vim 7.3 and persistent undo isn't working for me (I need to have `set undofile` to get the persistent undo). Do other settings interfere with the new feature, e.g. `nobackup` or `noswapfile`? – Dennis May 24 '13 at 10:51
-
I think the cream non-cream-vim-installer also sets this enabled by default. – Josiah Yoder Apr 21 '15 at 14:18
-
2Oh man!! now I have to remember: `set nobackup set noswapfile set noundofile` in every _vimrc if I don't want puppy tracks??!! You'd think ONE of those could default to off or something... – ebyrob Jan 05 '18 at 17:52
-
12It appears as if vim 8 (at least 8.0.427) has this feature turned on by default. YMMV of course... – Chuck Wolber Feb 15 '18 at 00:58
-
Just notifying that Vim installed on Windows with the default .exe installer found at vim.org does enable this option by default. At least as of 8.2. – Atralb Oct 17 '20 at 21:16
Took me a while to find where to actually put the :set noundofile
command. I am new and I’ll just reply with how I made it not do backups.
- Open vim.
- Type in command mode
:e $HOME/.vimrc
- Write
:set noundofile
- Save & quit:
:wq

- 18,263
- 4
- 39
- 47

- 131
- 1
- 5
-
It works for my use case, that is a little bit different: using Vim inside ConEmu on Windows. Thanks! – Mário Meyrelles May 10 '20 at 21:15
-
I got undofiles by default on vim windows installer. Your guide helped me, thanks! – Cardin Aug 21 '20 at 04:44
-
2Please don't! Undo is an extremely valuable feature. You just need to define an [undodir](https://stackoverflow.com/a/64352537/6419007). – Eric Duminil May 28 '21 at 09:31
-
Another possible way to avoid vim creating undo files everywhere is set set the undodir to some existing directory, e.g.
if has('persistent_undo') "check if your vim version supports
set undodir=$HOME/.vim/undo "directory where the undo files will be stored
set undofile "turn on the feature
endif

- 66,836
- 64
- 257
- 336
-
2Exactly. Vim undo is an extremely valuable tool (when it doesn't litter your folders). I love `:earlier 30m`, for example. – Eric Duminil May 28 '21 at 09:31