netrw always re-trigger FileType on enters file event loaded buffer
Maintainers usually reply within 13 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- vim
- Domain
- tooling
Research direction
Start with netrw's NetrwGetFile path and the filetype detect call described in the issue, then inspect how LoadFTPlugin handles b:undo_ftplugin. Reproduce the steps with the Vim9 test file and :Explore. Done means entering the file does not retrigger FileType or remove user settings such as b:match_skip, omnifunc, formatexpr, and foldexpr.
Written by the indexing model from the issue text.
Description
Steps to reproduce
- Write this to a test file.
vim9script
packadd netrw
augroup Test
autocmd!
autocmd VimEnter * call Test()
augroup END
def Test()
set filetype=vim
b:match_skip = 10
echo 'done'
enddef
- Run:
vim --clean -S test test
-
:echo b:match_skipreturns10. -
Run:
:Explore<CR>
-
Choose the test file and press
<CR>to enter the test file. -
echo b:match_skipreturns:
E121: Undefined variable: b:match_skip
https://github.com/user-attachments/assets/b84e813d-32fc-4e87-b471-51d08b408238
Because when netrw enters a file, it uses filetype detect to initialize native or remote files. filetype detect will trigger FileType * again, which calls LoadFTPlugin(). It will execute b:undo_ftplugin.
...
" Moved the filetype detect here from NetrwGetFile() because remote files
" were having their filetype detect-generated settings overwritten by
" NetrwOptionRestore.
if &ft != "netrw"
filetype detect
endif
...
def LoadFTPlugin()
if exists("b:undo_ftplugin")
# We assume b:undo_ftplugin is using legacy script syntax
legacy exe b:undo_ftplugin
unlet! b:undo_ftplugin b:did_ftplugin
endif
var s = expand("<amatch>")
if s != ""
if &cpo =~# "S" && exists("b:did_ftplugin")
# In compatible mode options are reset to the global values, need to
# set the local values also when a plugin was already used.
unlet b:did_ftplugin
endif
# When there is a dot it is used to separate filetype names. Thus for
# "aaa.bbb" load "aaa" and then "bbb".
for name in split(s, '\.')
exe 'runtime! ftplugin/' .. name .. '.vim ftplugin/' .. name .. '_*.vim ftplugin/' .. name .. '/*.vim'
endfor
endif
enddef
If commands in b:undo_ftplugin are the same as the variables or options initialized by users, they will be undone and initialized back to the values from the built-in ftplugin file. This breaks user updates.
This is especially problematic in LSP scenarios. It often conflicts with some settings in built-in ftplugin files, such as omnifunc, formatexpr, and foldexpr.
btw NerdTree not have this problem, because it use :edit to enters file.
Expected behaviour
netrw won't be use filetype detect to re-treggier autocmd FileType
Version of Vim
:version VIM - Vi IMproved 9.2 (2026 Feb 14, compiled Aug 1 2026 21:48:38) Included patches: 1-892
Environment
Linux debian 7.1.3+deb14-amd64 #1 SMP PREEMPT_DYNAMIC Debian 7.1.3-1 (2026-07-04) x86_64 GNU/Linux
Logs and stack traces
- Dominant language
- Vim Script
- Stars
- 41.4k
- Forks
- 6.2k
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from vim/vim
-
autoconf failes to find libsodium even when present due to implicit function declarationPossibly taken @coderjoe claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 13 days
-
`json_decode()` uses a number as a string pointer when 'encoding' has no converterPossibly taken @mattn claimed this 7 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 13 days
-
GTK4 build's v:servername is prefixed with $XDG_RUNTIME_DIR/vimMay be free again A pull request for this issue was closed without being merged. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 13 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 13 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 13 days
Similar issues
-
Needs Triage
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
enhancement good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
anthropics/skills#2328 ·
Maintainers usually reply within 1 day
-
bug good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
tonydzi/sqlite-graph-memory#133 · 1 comment ·
Maintainers usually reply within 1 day
-
area: build-and-ci S3: minor
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
manaflow-ai/cmux#72257 ·
Maintainers usually reply within 1 day