在 vim 中就地编辑文件 [英] Edit a file in-place in vim
问题描述
通常,您实际上不会在 vim 中编辑文件.如果你运行 vim foo
,编辑、写入并退出,vim 会取消链接 foo
并创建一个新文件和一个名为 foo
的新链接.但是,如果文件有多个链接,那么 vim
实际上会修改文件.例如:
Normally, you don't actually edit a file in vim. If you run vim foo
, edit, write and quit, vim unlinks foo
and creates a new file and a new link named foo
. But, if the file has more than one link, then vim
actually modifies the file. For example:
$ ls -i foo
19428852 foo
$ vi foo
$ ls -i foo
19428857 foo
$ ln foo bar
$ vi bar
$ ls -i bar
19428857 bar
我一直在寻找一种实际编辑文件的方法,似乎有两种选择.使用 ed
,或使用 vim
但确保在我编辑之前至少有两个指向该文件的链接.我想这个问题是学术性的,因为如果只有一个链接,vim 创建一个新文件并不重要,如果在编辑过程中创建链接,vim 似乎会做正确的事情,但我很好奇:
I've been looking around for a way to actually edit a file, and it seems there are two choices. Use ed
, or use vim
but ensure that there are at least two links to the file before I edit. I suppose the question is academic, as it doesn't really matter that vim creates a new file if there is only one link, and vim seems to do the right thing if links are created while the editing is underway, but I'm curious:
是否可以让 vim 始终编辑文件而不创建新文件?
is it possible to make vim always edit the file, and not create a new one?
推荐答案
查看 backupcopy
选项的帮助,特别是 crontab
的注释.简短的回答是
Check out the help for the backupcopy
option and the notes on crontab
in particular. The short answer is
:set backupcopy=yes
这篇关于在 vim 中就地编辑文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!