0

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.

5
  • 2
    You can try running :setl, which should show all non-default local settings. Jan 23, 2023 at 9:37
  • @MartinTournoij After reading all the :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.) Jan 23, 2023 at 13:07
  • What happens when you try to use :bn? Do you get an error? Or simply nothing happens? Jan 23, 2023 at 13:14
  • @MartinTournoij: Say I have two windows(and both are loaded with a unique buffer): A, which is generated by the plugin, and B, which is just a normal window I opened for editing my program. In my current situation, if I call :bn on A, the behavior is like I were calling :bn on B. Jan 23, 2023 at 13:22
  • @MartinTournoij Hi, sorry to tag you again. I just solved my problem brute-forcibly(details below) and you could skip my problem(if you're still doing it) so your time will be saved. I really appreciate your kindness on those reasonable further questions. Happy new year and have a good day. Jan 23, 2023 at 14:38

2 Answers 2

0

set nomodifiable

help 'nomodifiable'

4
  • Thanks for your reply. But the result of :set modifiable? is modifiable and I still cannot use :bn to change the buffer of that window to another one after testing. Jan 23, 2023 at 6:09
  • 1
    Well, even if you set 'nomodifiable' a user can simply ':set modifiable' and start editing the buffer. So it's not completely unchangeable. Jan 23, 2023 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.
    – dza
    Jan 23, 2023 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, 2023 at 15:47
0

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 autocmds 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.)

6
  • 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, 2023 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, 2023 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, 2023 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, 2023 at 15:52
  • 1
    correct, I meant the command as I wrote it, without a | in between. Another way to break it: set eventignore=BufWinEnter,BufWinLeave , :bn Jan 23, 2023 at 17:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.