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

**URL:** <https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971>\
**Category:** Help\
**Created:** [January 9, 2022, 12:43pm UTC](https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971 "2022-01-09T12:43:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vrugar0](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/v/439d5e/32.png) [@vrugar0](https://discuss.kakoune.com/u/vrugar0)\
**Post date:** [January 9, 2022, 12:43pm UTC](https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971/1 "2022-01-09T12:43:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [January 9, 2022, 1:10pm UTC](https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971/2 "2022-01-09T13:10:21Z")

</div>

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:

- [Issue 2360](https://github.com/mawww/kakoune/issues/2360#issuecomment-427547601)
- [Issue 1496](https://github.com/mawww/kakoune/issues/1496)

---

<div class="post-metadata">

**Author:** ![vrugar0](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/v/439d5e/32.png) [@vrugar0](https://discuss.kakoune.com/u/vrugar0)\
**Post date:** [January 9, 2022, 7:54pm UTC](https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971/3 "2022-01-09T19:54:49Z")

</div>

Thanks for your reply and the links.

---

<div class="post-metadata">

**Author:** ![JJK96](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/jjk96/32/305_2.png) [@JJK96](https://discuss.kakoune.com/u/JJK96)\
**Post date:** [January 11, 2022, 12:49pm UTC](https://discuss.kakoune.com/t/question-writing-w-a-scratch-buffer-to-a-file/1971/4 "2022-01-11T12:49:36Z")

</div>

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.
