Skip to content

fix(new-tutor): set buftype to 'nowrite' instead of 'nofile'#18613

Closed
brianhuster wants to merge 1 commit intovim:masterfrom
brianhuster:tutor
Closed

fix(new-tutor): set buftype to 'nowrite' instead of 'nofile'#18613
brianhuster wants to merge 1 commit intovim:masterfrom
brianhuster:tutor

Conversation

@brianhuster
Copy link
Contributor

Problem:
After I have opened the tutor with :Tutor, then I close its window with :q, then if I run :Tutor to open the tutor again, it will open an empty buffer instead of the tutor content. This is a very confusing behavior.

Related issue neovim/neovim#36228

Solution:
I believe the point of set buftype=nofile is just to prevent users from accidentally writing changes to the tutor file, so why not use nowrite instead?

@brianhuster brianhuster changed the title fix(tutor): set buftype to 'nowrite' instead of 'nofile' fix(new tutor): set buftype to 'nowrite' instead of 'nofile' Oct 21, 2025
Problem:
After I have opened the tutor with `:Tutor`, then I close its window
with `:q`, then if I run `:Tutor` to open the tutor again, it will open
an empty buffer instead of the tutor content. This is a very confusing
behavior.

Solution:
I believe the point of `set buftype=nofile` is just to prevent users
from accidentally writing changes to the tutor file, so why not use
`nowrite` instead?
@zeertzjq zeertzjq changed the title fix(new tutor): set buftype to 'nowrite' instead of 'nofile' fix(new-tutor): set buftype to 'nowrite' instead of 'nofile' Oct 21, 2025
@habamax
Copy link
Contributor

habamax commented Oct 21, 2025

I can't reproduce it with the steps provided.

https://asciinema.org/a/tgKyl8dmRSrIdQ3BsW0DragCT

@habamax
Copy link
Contributor

habamax commented Oct 21, 2025

However if you :e within :Tutor it will wipe out the buffer contents. Here set buftype=nowrite doesn't help.

Or just do :Tutor and then again :Tutor. Here set buftype=nowrite helps.

I believe a better solution might be to come up with BufReadCmd to populate buffer properly on occasional :e and other related commands.

@habamax
Copy link
Contributor

habamax commented Oct 21, 2025

If you add autocmd! BufReadCmd <buffer> :Tutor

" Enables/disables interactive mode.
function! tutor#EnableInteractive(enable)
    let enable = a:enable
    if enable
        setlocal buftype=nowrite
        setlocal concealcursor+=inv
        setlocal conceallevel=2
        call tutor#ApplyMarks()
        augroup tutor_interactive
            autocmd! TextChanged,TextChangedI <buffer> call tutor#ApplyMarksOnChanged()
            autocmd! BufReadCmd <buffer> :Tutor
        augroup END
...

Together with set buftype=nowrite it would also fix issue with :e.

@habamax
Copy link
Contributor

habamax commented Oct 21, 2025

Well, it needs to be smarter: it should know what tutorial was loaded into the buffer and read it back within BufReadCmd.

PS, original tutorial ftw :)

@brianhuster
Copy link
Contributor Author

brianhuster commented Oct 22, 2025

Or just do :Tutor and then again :Tutor. Here set buftype=nowrite helps.

This is what I was trying to solve.

Well, it needs to be smarter: it should know what tutorial was loaded into the buffer and read it back within BufReadCmd.

Tutor is not a part of anyone's workflow, so I don't want to put too much time on it. I also support removing the new tutor btw. But until then, to avoid confusion to users, it should at least be reliable

@chrisbra
Copy link
Member

Thanks. Let's also make it :drop instead of edit, so it works even when the current buffer is modified

@chrisbra chrisbra closed this in 9978bb7 Oct 25, 2025
@brianhuster
Copy link
Contributor Author

Let's also make it :drop instead of edit, so it works even when the current buffer is modified

@chrisbra Why doesn't :edit work when the current buffer is modified? Can you please elaborate on that?

Also, you have not explained that change in the commit message.

@chrisbra
Copy link
Member

Why doesn't :edit work when the current buffer is modified? Can you please elaborate on that?

Try yourself: :set modified| :e and notice the E37.

Also, you have not explained that change in the commit message.

Indeed, but now it is set in stone 🤷

zeertzjq added a commit to zeertzjq/neovim that referenced this pull request Oct 27, 2025
Problem:  :Tutor may not work as expected
Solution: set buftype=nowrite instead of nofile
          (Phạm Bình An)

closes: vim/vim#18613

vim/vim@9978bb7

Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
zeertzjq added a commit to neovim/neovim that referenced this pull request Oct 27, 2025
Problem:  :Tutor may not work as expected
Solution: set buftype=nowrite instead of nofile
          (Phạm Bình An)

closes: vim/vim#18613

vim/vim@9978bb7

Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
github-actions bot pushed a commit to neovim/neovim that referenced this pull request Oct 27, 2025
Problem:  :Tutor may not work as expected
Solution: set buftype=nowrite instead of nofile
          (Phạm Bình An)

closes: vim/vim#18613

vim/vim@9978bb7

Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
(cherry picked from commit fb6fd17)
github-actions bot pushed a commit to neovim/neovim that referenced this pull request Oct 27, 2025
Problem:  :Tutor may not work as expected
Solution: set buftype=nowrite instead of nofile
          (Phạm Bình An)

closes: vim/vim#18613

vim/vim@9978bb7

Co-authored-by: Phạm Bình An <phambinhanctb2004@gmail.com>
(cherry picked from commit fb6fd17)
@brianhuster brianhuster deleted the tutor branch January 8, 2026 15:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants