There is a text like this
As of initscripts-2012.07.5, the default format of /etc/rc.conf and
/etc/crypttab have changed. See their respective man pages for
more details.
--BEGIN--
The purpose of this change is to unify the configuration of systemd
and initscripts. This will allow us to share code and documentation,
and should make maintenance of initscripts simpler in the long-run.
--END--
The old format is still supported, so old config files should still
work unchanged.
Hopefully --BEGIN--
Delete all the lines between --END--
. Is there any direct method for vim?
Another additional question is how to add a piece of content when there is already a --BEGIN--
mark.
The above all hope to process text files in a scripted manner.
Just an example, the number of lines between --BEGIN--,--END-- is uncertain
Marking this manually is a bit laborious. The actual file is not small and has a similar structure
More.
:g/--BEGIN--/,/--END--/d
如果要同时删除前后的空行
:g/--BEGIN--/-1,/--END--/+1d
vim可以做到,
在命令模式下:
其中的\_是关键,这个可以匹配多行。
已经有--BEGIN--标识如何替换,这个也可以用上面的替换思路来做
:%s/^--BEGIN--/&要替换的内容/g
光标移至开始部分
Esc v 进行view模式
j 向下选中操作部分
d 删除 x 剪切 两个都可以
既然要脚本化,就用 sed 呗:
ndd,n为要删除的行数。