0

As title. I'm in a situation where a file is loaded into a buffer that is not listed in the buffers from the list :ls. So I want to transfer the content of the current unlisted buffer to an existing buffer(supposed to be a [No Name]).

Or put it simple: Is it possible to make an unlisted buffer get listed?

enter image description here

5
  • 1
    Welcome to Vi and Vim! Does :set buflisted resolve your issue? See `:help 'buflisted'. How come you're getting an unlisted buffer? And what is not working because the buffer is unlisted, are you having trouble saving the file or something like that? What error do you get when you try such an operation?
    – filbranden
    Apr 19, 2022 at 6:07
  • 1
    @filbranden: Thanks for your good questions. I think the first one solves my question. I will answer myself later if appropriate, or delete it if not. What do you think?
    – Kindred
    Apr 19, 2022 at 10:00
  • 1
    Yes, go ahead and post a self-answer if that answered your question! If you'd like to also edit your question to make it clearer what the issue you were having was (trouble saving?), that would be excellent. Thanks!
    – filbranden
    Apr 19, 2022 at 14:30
  • FWIW, I'm not sure what the screenshot has to do with anything: if you want readers to look at code, please don't post images of text
    – D. Ben Knoble
    Apr 19, 2022 at 14:34
  • @D.BenKnoble: Sorry my bad. I was trying to demo the there are two [No Name] at the above and both were not selected. So the content of the current buffer is actually not listed.
    – Kindred
    Apr 20, 2022 at 3:39

1 Answer 1

0

The problem is more complex than what I described in the OP. But, in short, if you have the information that your current file content is loaded in a buffer that is not listed (by not listed I meant those buffers which won't shown by :ls) Then some ways to "stage" it can be:

  1. edit
  2. set buflisted (I take this approach)
vim.keymap.set('n', ';', function ()
  if vim.bo.filetype ~= 'neo-tree' then
    vim.cmd('NeoNoNameClean')
  end
  vim.cmd('Neotree float toggle reveal_force_cwd dir=' .. vim.fn.getcwd())
  if vim.bo.filetype ~= 'neo-tree'
    and not vim.api.nvim_buf_get_option(0, 'buflisted') then
      vim.cmd('set buflisted')
  end
end, NOREF_NOERR_TRUNC)
1
  • Welcome to Vim. You should not use the answer section to precise your question. It will confuse the future readers. Could you please instead edit your original question? Apr 21, 2022 at 3:11

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.