3

I have a script which performs some action and then pipes the stdout to Neovim so that I can look at it with syntax highlighting and do all the other nice things I can do with vim.

However, as this is a temporary file just used for inspecting the (possibly very long) output of the command, I almost never want to actually save the file. When I :q to exit, I get E37: No write since last change (add ! to override) as expected.

I've tried :set ro but I still get E37 when exiting. I could of course train myself to just use :q! for this particular scenario, but I'd rather come up with a better solution.

Is there some argument I can pass to nvim in my script that will prevent E37 when I :q?

5

You can use :set buftype=nowrite or :set buftype=nofile

From :help 'buftype':

nofile        buffer which is not related to a file and will not be
                written
nowrite       buffer which will not be written

[..]


"nofile" and "nowrite" buffers are similar:
both:           The buffer is not to be written to disk, ":w" doesn't
                work (":w filename" does work though).
both:           The buffer is never considered to be 'modified'.
                There is no warning when the changes will be lost, for
                example when you quit Vim.
both:           A swap file is only created when using too much memory
                (when 'swapfile' has been reset there is never a swap
                file).
nofile only:    The buffer name is fixed, it is not handled like a
                file name.  It is not modified in response to a :cd
                command.
both:           When using ":e bufname" and already editing "bufname"
                the buffer is made empty and autocommands are
                triggered as usual for :edit.

In your case, it doesn't matter all that much which one you use.

  • This is exactly what I was looking for! Updated my script to pipe to nvim -c "set buftype=nofile" - and it works just the way I wanted it to. – Ben May 17 '17 at 14:05

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.