Lock some text in vim to prevent changes

I am looking for a way to prevent the modification of a portion of the vim buffer. I know that you can lock the buffer to prevent all changes inside, but I would like to do the same for multiple lines or paragraphs.

Any idea if this is possible?

Cheers, B

+3
source share
3 answers

Well, as I know, vim cannot do this. The text in the vim buffer is just a string without any property that can be attached to them. Thus, "readonly" can only be for the entire buffer, but not for specific characters, although emacs is able to add text properties to allow some characters in the buffer to read only.

, - . , .

1. "setlocal buftype = nofile", , , .
2. ( )
3.edit temp buffer.
4. , "" , .

, vim, .

+1

, ,

0

If the "protected" area of ​​the text is easily defined (i.e. by its position in the file or regular expression), you can try to write a function BufWritePrethat checks this region and gives an error if it has been changed. I turned to this when I wanted to prevent Saving a file with an invalid crease structure.

Presumably this will be due to saving the source text in a variable when loading the file, and this may have performance implications.

Hope this helps.

0
source

All Articles