gitignore.nvim icon indicating copy to clipboard operation
gitignore.nvim copied to clipboard

Buffer with name '.gitignore' already exists, didn't name buffer!

Open jeeeem opened this issue 5 months ago • 2 comments

It does appends the new gitignore lines, but not in the existing .gitignore. It creates an untitled buffer.

Image
return {
  "wintermute-cell/gitignore.nvim",
  cmd = "Gitignore",
  config = function() require "gitignore" end,
}

jeeeem avatar Jul 29 '25 11:07 jeeeem

I face exactly the same issue :(

My config looks like this:

return {
  'wintermute-cell/gitignore.nvim',
  config = function()
    local gitignore = require 'gitignore'
    -- project root + '.gitignore' file
    local file_path = vim.fn.expand '%:p:h' .. '/.gitignore'

    vim.keymap.set('n', '<leader>gI', function()
      gitignore.generate(file_path)
    end, { desc = 'Generate .gitignore' })
  end,
}

It works well if the .gitignore file doesn't exist.

janosmiko avatar Jul 30 '25 13:07 janosmiko

Same issue but i can propose a solution (i am new to nvim so idk if possible): generate() checks if the current buffer is label as .gitignore (or any buffer open with that label). If so than write the template on the cursor position in that buffer Otherwise create the file and if is already created than ask the user if want to override it (if the opts gitignore_nvim_overwrite is false )

P.S Should be label as bug for those who like to resolve it.

valentimarco avatar Nov 10 '25 01:11 valentimarco