diff --git a/src/nvim/context.c b/src/nvim/context.c index 11e15d7466..19d3712847 100644 --- a/src/nvim/context.c +++ b/src/nvim/context.c @@ -491,6 +491,8 @@ bool ctx_switch(CtxSwitch *cs, win_T *wp, tabpage_T *tp, buf_T *buf, CtxSwitchFl wp = ctx_win_prep(cs, buf); // Leave the window we entered "from". leaving_window(curwin); + // We will soon enter "buf" and may have to copy buffer options. + buf_copy_options(buf, BCO_ENTER | BCO_NOHELP); prevwin = curwin; } assert(win_valid(wp)); diff --git a/test/functional/vimscript/buf_functions_spec.lua b/test/functional/vimscript/buf_functions_spec.lua index 23262acc81..d04dc5a9c2 100644 --- a/test/functional/vimscript/buf_functions_spec.lua +++ b/test/functional/vimscript/buf_functions_spec.lua @@ -324,3 +324,19 @@ describe('setbufvar() function', function() eq('Vim:E928: String required', pcall_err(fn.setbufvar, '', '&errorformat', true)) end) end) + +describe('bufload() function', function() + before_each(function() + t.write_file(fname, 'foo\n') + end) + after_each(function() + os.remove(fname) + end) + it('does not set hidden buffer as modified #41148', function() + local buf = fn.bufadd(fname) + fn.bufload(buf) + api.nvim_command('edit ' .. fname) + eq(true, api.nvim_buf_is_loaded(buf)) + eq(false, api.nvim_get_option_value('modified', { buf = buf })) + end) +end)