Question: Writing(:w) a scratch buffer to a file

hi, I am a new Kakoune user and have been using it as my main editor for a month now. I have a question regarding the ‘:w’ command.

In vim, if a new buffer is created using the ‘:enew’ command and then the ‘:w’ command is used to write to a file, the buffer gets renamed. Subsequent writes to this buffer become successful.

In Kakoune, if I create a new buffer using ‘:e -scratch’ and then ‘:w’ command is used to write to a file, buffer does not get renamed and subsequent ‘:w’ command displays this error - 'cannot write a non-file buffer without a filename’use.

So, I usually use these commands to save a scratch buffer to a file

:rename-buffer -file “filename” and then issue ‘:w’ command.

I am wondering if this is the correct method or is there an alternative way to achieve the behavior like vim’s?

Thanks

1 Like

I’m afraid that’s just the way it works at the moment. Although it’s clear there’s room for improvement, there’s been some discussion about what the best behaviour would be:

2 Likes

Thanks for your reply and the links.

It’s not that difficult to make a write hook which does something like what you describe. Use the bufwritepre hook. Edit: It seems that that hook is not executed because the cannot write a non-file buffer without a filename is thrown before.

1 Like