惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
Engineering at Meta
Engineering at Meta
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog
WordPress大学
WordPress大学
Jina AI
Jina AI
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
酷 壳 – CoolShell
酷 壳 – CoolShell
阮一峰的网络日志
阮一峰的网络日志
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
G
Google Developers Blog
C
Check Point Blog
月光博客
月光博客
L
LangChain Blog
GbyAI
GbyAI

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN Mintty Tips and Configurations
File Backup in Neovim
2019-11-16 · via jdhao's digital space

There are several options related to file backup behavior in Vim/Nvim.

  • backup
  • writebackup
  • backupdir
  • backupcopy
  • backupext

In this post, I will explain how these options are related to each other.

Option backup controls whether to make a physical backup when writing a file.

Option writebackup makes sure that a file backup be made before overwriting a file. The backup will be removed when the file is successfully written, unless backup option is also on. It reduces the risk that your file is destroyed if something goes wrong when you are writing the file to disk. For more info about using backup and writebackup together, see :h backup-table.

The option backext controls the extension used for backup files. backupext will be appended to the backup file names (default is ~). For example, if your file is test.txt and backupext is .bak, the backup file name will be test.txt.bak.

The option backupdir controls where the backup file will be placed. It is a list of directories (comma separated) to put the backup files. The first item in this option will be used. You must make sure that the backup directory exists, or you will see the following error when writing a file:

E510: Can’t make backup file (add ! to override)

Use the following setting to deal with this error:

let g:backupdir=expand(stdpath('data') . '/backup')
if !isdirectory(g:backupdir)
   mkdir(g:backupdir, "p")
endif
let &backupdir=g:backupdir

There is also an option backupcopy, which needs special attention. The value of backupcopy can be yes, no or auto:

  • yes: it will copy the original file to the backup location and overwrite the original file.
  • no: it will rename the original file (i.e., move it to the backup directory) and write a new file with the same name.
  • auto: Nvim will choose whatever works best for you.

Note that for some applications, you may want to set backupcopy to yes to avoid issues.

References#