Hacker News new | past | comments | ask | show | jobs | submit login

Oh, and man… never ever let Vim write a backup file! They did that in the 70’s. Use modern ways for tracking your changes, for God’s sake.

set nobackup set noswapfile

backup files are one thing, but turning off swap files is a terrible idea. vim can crash, you can accidentally close the window, your ssh session can die, etc. if you exit vim cleanly then the swap files will be transparent, so i don't see the point in disabling them.




or just do:

set backupdir=./.backup,.,/tmp

set directory=.,./.backup,/tmp

This way, if you want your backups to be neatly grouped, just create a directory called '.backup' in your working directory. Vim will stash backups there. The 'directory' option controls where swap files go. If your working directory is not writable, Vim will put the swap file in one of the specified places.

(http://vim.wikia.com/wiki/Remove_swap_and_backup_files_from_...)


    set backupdir=~/.vim/backup//
    set directory=~/.vim/swp//
The double tailing slash will store files using full paths so if you edit two different models.py files you won't clobber your swap or backups.


Oh man, this is awesome. Too bad it's vim-specific and not a shell built-in, which would be handy.


the minute I've read it I went and set the noswapfile option. I don't care if vim crashes, I save all the time. if it crashes I will just repeat the last edit. The stale swapfiles etc has caused me more time wasted over the years then lost edits.

But, I soon realized that noswapfile has another problem which caused me to disable it after all: it will allow you to open same file in more then one vim editor instance. And this is really asking for troubles.

It is less of a problem with graphical vim as you can use "autoread" to sync changes between instances, but it is a disaster on console.


I too very much happy after getting these two option. By looking those swap file and backup file I started hating vim. Why on earth it is creating all the un-necessary stuffs (though they useful at some case). Now for newbie like me I love this tips :)


so far, swap files have caused me more headache than anything else. I'm a paranoid maniac and I save every minute or two, so worst case I'll repeat a minute worth of coding.

What really ends up happening is I try to edit a file and something annoying pops up telling me about something requiring my attention (swap file already exists .. read only mode .. bla bla). In other words, it's just a distraction, most of the time.


Until it saves your ass. Which will happen, if you use vim for a few years.

You can configure it to put your swap files in a canonical dir, instead of polluting the directory you're editing files in:

set backupdir=/var/tmp,/tmp

set directory=/var/tmp,/tmp

Now you can just nuke the swap files in one swoop:

rm -rf /var/tmp/*.swp


Or cron-job the pruning.


Swap files can save you from editing the same file in two vim instanstances as once. Possibly overwriting each other.


Screen can help with the accidental closing of a window or a dropped ssh session. You can even restart X and just reattach to the daemon when you log back in.


> vim can crash

It can?


Never had vim crash, but I've had the OS crash. Or X server. Better safe than sorry.


yes, i've had it crash once in a rare while.

Vim: Caught deadly signal SEGV




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: