In vim 8, is it possible to insert visually blank regions into a window without modifying the underlying buffer?


I am writing a plugin (my first!) to assist me in updating patch files. The idea is very similar to a three-way-diff but with a patch file in the center region. The idea is to be able to modify the patch hunks to apply to files which have changed, usually due to updating an underlying BSP in Yocto. As the patches are edited I plan to update things like the hunk offsets + context and to use highlights to display breakages when applying the patch.

To make this process visually intuitive, I intend to have all three buffers "joined" so that scrolling one scrolls all. This is similar to many diff tools. Now, since there will be different (but related) content in each of the buffers, I want to visually "pad" each to the same final length. To do this, I could just add regular line breaks.

The rub here is that I then want to be able to write the file to disk without these newlines. Worse, I can't blindly strip whitespace as it may be used for context in some of the hunks.

I have considered adding sentinel lines in the buffer and rendering them as blanks and stripping them on write but I am not sure how this would be achieved. In addition, Vim has diff mode so I would expect this to be a somewhat solved problem.

  • 1
    not really possible. You can only add real blank lines, remember where you added it and remove those on writing the buffer (using e.g. a BufWritePre autocommand). Sep 28 '21 at 17:55
  • Scrolllock or similar might be of help
    – D. Ben Knoble
    Sep 28 '21 at 23:17
  • @ChristianBrabandt: Is there a way to use some value that is replaced with a newline when viewing or would this just have to be done with list? Additionally, how would I keep track of what gets inserted by the user / handle user-configured line wrapping? Sep 29 '21 at 16:06
  • @D.BenKnoble: This is pretty close to what I am after. Seems like this plus modifying the buffers to be of equal length will do what I want. Sep 29 '21 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.