As title. In fact, I just encountered a situation where I cannot change the buffer of the current window, which is created by some plugin. So I guess there might be some window/buffer option(s) to prevent the current buffer from being changed.
2 Answers
set nomodifiable
-
Thanks for your reply. But the result of
:set modifiable?
ismodifiable
and I still cannot use:bn
to change the buffer of that window to another one after testing. Jan 23 at 6:09 -
1Well, even if you set 'nomodifiable' a user can simply ':set modifiable' and start editing the buffer. So it's not completely unchangeable. Jan 23 at 7:49
-
@job_start thats not what I wrote, I wrote
set nomodifiable
I'm not aware of any other option like this, so I still believe answer is correct.– dzaJan 23 at 15:18 -
Understood. In fact, I also tried
:set nomodifiable
, and the results are the same: I cannot switch the buffer of that window. Jan 23 at 15:47
In short, there is no built-in option to prevent you from switching(I used the word changing and now I think that is misleading since my question is not about changing the content of a file) the buffer of a given window. (Since the repo. has <200 commits there, so I read through those commit messages and found the one that caused the behavior.)
In that commit, the author uses a function that will be called on two autocmd
s under a augroup
named DapuiWindowsSetup
: BufWinEnter,BufWinLeave
to achieve the behavior described in my OP. (This might be a piece of useful information if you want to implement the reverse: prevent switching the buffer of a given window, as the commit did.) By deleting that augroup
I get the original behavior I want. (Regarding the LICENSE of that Repo., I won't post the code here.)
-
that is still not safe. You can still do
:noa :bn
and switch away. In short, there is no way to prevent a user from doing this Jan 23 at 14:50 -
Is it github.com/rcarriga/nvim-dap-ui? The MIT License should explicitly permit you to post the patch as long as you maintain the License text (IANAL)?– D. Ben Knoble ♦Jan 23 at 15:34
-
@ChristianBrabandt: Thanks for your comment as I never know about
:noa
. But after my trying (I tried:noa | bn
) the plugin indeed prevent me from switching the buffer. Jan 23 at 15:38 -
1@job_start the command would be
:noautocmd bnext
;noautocmd
is a modifier. The bar-separator in your example is what caused it to fail (since:noa
by itself is a nop).– D. Ben Knoble ♦Jan 23 at 15:52 -
1correct, I meant the command as I wrote it, without a
|
in between. Another way to break it:set eventignore=BufWinEnter,BufWinLeave
,:bn
Jan 23 at 17:27
:setl
, which should show all non-default local settings.:h ...
from the result of:setl
, I found that:set buflisted
the most promising one. But then I still got the same result: when I called:bn
on the window it instead changed the buffer of another window. (still enjoy the try-and-error process since I never know there is a way to list all the local options, might be helpful in the future.):bn
? Do you get an error? Or simply nothing happens?A
, which is generated by the plugin, andB
, which is just a normal window I opened for editing my program. In my current situation, if I call:bn
onA
, the behavior is like I were calling:bn
onB
.