[vim] vim creates large swp files

368 views
Skip to first unread message

Kirill Ryzhkov

unread,
Feb 26, 2021, 2:10:30 AM2/26/21
to vim_dev

Hi Vim developers!
I use vim on Linux all the time and found a problem with creating just huge swp files that can take up all the hard disk space.
If you open vim and copy a large text that can cause the linux console to hang and then you force close the console, after a couple of days the swp file size can reach hundreds of gigabytes. I have already encountered this problem twice and each time I had to look for where these swp files were created in which directory.
I am using vim version 8.0.1453.
 
Maybe there is a new version that fixes this bug ?
 
Thanks!

Bram Moolenaar

unread,
Feb 26, 2021, 7:58:11 AM2/26/21
to vim...@googlegroups.com, Kirill Ryzhkov
No. And it's not likely a problem that can be fixed.

The simplest way to handle this is to unload the buffer and open it
again. Then a new swapfile will be used.

A swapfile of hundreds of gigabytes is very unusual though. I don't see
how you can get that if you copy a large text. Perhaps you have some
filter that causes lines to get longer, so they have to be moved around?
Or you work with very long lines, such as XML without any line breaks.
Can you give a reproducible example (without sending us a Gbyte file, of
course).

You can also disable the swapfile, although you then lose the ability to
restore your work after a crash.

--
Every exit is an entrance into something else.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Charles Campbell

unread,
Feb 26, 2021, 5:27:34 PM2/26/21
to vim...@googlegroups.com
No, but since you're a linux user you can handle this problem yourself
with a cron job.
Use  crontab -e  to edit the cron table commands. (cron is a daemon that
runs at your specified times to do some work).
# # # # # /path/to/script

#1: minute (0-59)
#2: hour (0-23)
#3: day-of-month (1-31)
#4: month (1-12)
#5: day-of-week (0-6)

The shell script or command you have cron run can then check for size
for those files which look like swap files, and if they're too big and
too old; delete it.
For example:  ...time-spec-here..  /usr/bin/find "/home/username" -type
f -name '*.sw[a-z]' -atime 3 -size 2G -exec "/bin/rm" "{}" ";"

Note, I haven't tested the above line, and instead of removing the file,
you may want to move it to some directory instead (to see if the command
is doing what you want).
Suggested reading: man crontab, man find. UAYOR.

Chip Campbell

Reply all
Reply to author
Forward
0 new messages