Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

autocmd BufRead * autocmd FileType <buffer> ++once doesn't work #21920

Open
cryptomilk opened this issue Jan 20, 2023 · 8 comments
Open

autocmd BufRead * autocmd FileType <buffer> ++once doesn't work #21920

cryptomilk opened this issue Jan 20, 2023 · 8 comments
Labels
bug issues reporting wrong behavior documentation

Comments

@cryptomilk
Copy link
Contributor

Describe the bug

The autocmd described in :help restore-cursor doesn't work.

Steps to reproduce

A simple reproducer would be:

autocmd BufRead * autocmd FileType <buffer> ++once echo "wurst"

Expected behavior

It should print "wurst" once.

Neovim version (nvim -v)

0.8.2

Vim (not Nvim) behaves the same?

yes

Operating system/version

Fedora 37

Terminal name/version

konsole

$TERM environment variable

tmux-256color

Installation

system package manager

@cryptomilk cryptomilk added the bug issues reporting wrong behavior label Jan 20, 2023
@cryptomilk
Copy link
Contributor Author

I'm not sure if this is just a documentation issue.

The autocmd BufRead * set up an event and if it triggers, it wants to call autocmd FileType <buffer> ++once echo "wurst". This looks totally valid to me.

@zeertzjq
Copy link
Member

This works if you run it before filetype.lua is sourced, e.g, put it in init.vim or init.lua or pass it in --cmd, but not if you run it after startup because filetype.lua has already been loaded.

@cryptomilk
Copy link
Contributor Author

cryptomilk commented Jan 20, 2023

Ah, it needs to be BufReadPre

autocmd BufReadPre * autocmd FileType <buffer> ++once echo "wurst"

@clason
Copy link
Member

clason commented Feb 17, 2023

PR welcome! (We have already diverged from upstream for this snippet.)

@lewis6991
Copy link
Member

To clarify, the fix should be to run filetype.lua as the last BufRead event.

@zeertzjq
Copy link
Member

zeertzjq commented Feb 20, 2023

To clarify, the fix should be to run filetype.lua as the last BufRead event.

How is that possible without hardcoding that in C?

@lewis6991
Copy link
Member

It might not be possible without C changes. Otherwise, we should close this as "won't fix".

@clason
Copy link
Member

clason commented Feb 20, 2023

It might not be possible without C changes. Otherwise, we should close this as "won't fix".

No, we also could (and should) simply update the snippet in the docs -- that's the PR I had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug issues reporting wrong behavior documentation
Projects
None yet
Development

No branches or pull requests

4 participants