开发者

Protect foldmarkers in Vim

I have recently joined a software company that uses folded Emacs along with its own in-house compiler with additional checks for fold-structure, amongst other things. In particular, a compiler error is raised if incorrect foldmarkers are recognised (we use the foldmarks //{{{,//}}} ). As a long-time Vim user, I have been diligently writing my own Vimscript to emulate the Emacs mods.

The Emacs configuration prevents foldmarks from being edited "by hand" (e.g. accidental spaces, etc). Is there a way to achieve this in Vim? Once a foldmarker has been entered using zf, I don't want to be able to edit it manually.

Or am I pushing Vim to开发者_StackOverflow中文版o far? Surely not!

Thanks for your help.

Jonathan.


Preventing edits to parts of the buffer is hard to achieve. Apart from the "fold consistency check" already mentioned in the comments (to be executed before saving the buffer), an easy way is to highlight fold markers used in the wrong places as errors (like some syntaxes (vim, sh) do for illegal elements).

You can add these either by extending the filetype's syntax (if this is only for one / a few filetypes, and embedding the new syntax group in the existing comment groups is easy) via :syntax match ..., or for each window via matchadd().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜