{"id":35126450,"url":"https://github.com/wsdjeg/bufdel.nvim","last_synced_at":"2026-03-06T18:04:29.043Z","repository":{"id":326898620,"uuid":"1107089095","full_name":"wsdjeg/bufdel.nvim","owner":"wsdjeg","description":" delete buffers without changing windows layout","archived":false,"fork":false,"pushed_at":"2026-02-23T03:29:07.000Z","size":67,"stargazers_count":12,"open_issues_count":0,"forks_count":2,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-23T11:39:15.978Z","etag":null,"topics":["neovim-plugin"],"latest_commit_sha":null,"homepage":"","language":"Lua","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wsdjeg.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-11-30T15:01:27.000Z","updated_at":"2026-02-23T03:29:01.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/wsdjeg/bufdel.nvim","commit_stats":null,"previous_names":["wsdjeg/bufdel.nvim"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/wsdjeg/bufdel.nvim","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsdjeg%2Fbufdel.nvim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsdjeg%2Fbufdel.nvim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsdjeg%2Fbufdel.nvim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsdjeg%2Fbufdel.nvim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wsdjeg","download_url":"https://codeload.github.com/wsdjeg/bufdel.nvim/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wsdjeg%2Fbufdel.nvim/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30189489,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T17:33:53.563Z","status":"ssl_error","status_checked_at":"2026-03-06T17:33:51.678Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["neovim-plugin"],"created_at":"2025-12-28T03:00:30.389Z","updated_at":"2026-03-06T18:04:29.031Z","avatar_url":"https://github.com/wsdjeg.png","language":"Lua","readme":"# bufdel.nvim\r\n\r\nbufdel.nvim is a neovim plugin that helps you delete buffers without changing windows layout.\r\n\r\n[![GitHub License](https://img.shields.io/github/license/wsdjeg/bufdel.nvim)](LICENSE)\r\n[![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/wsdjeg/bufdel.nvim)](https://github.com/wsdjeg/bufdel.nvim/issues)\r\n[![GitHub commit activity](https://img.shields.io/github/commit-activity/m/wsdjeg/bufdel.nvim)](https://github.com/wsdjeg/bufdel.nvim/commits/master/)\r\n[![GitHub Release](https://img.shields.io/github/v/release/wsdjeg/bufdel.nvim)](https://github.com/wsdjeg/bufdel.nvim/releases)\r\n[![luarocks](https://img.shields.io/luarocks/v/wsdjeg/bufdel.nvim)](https://luarocks.org/modules/wsdjeg/bufdel.nvim)\r\n\r\n\u003c!-- vim-markdown-toc GFM --\u003e\r\n\r\n- [Requirements](#requirements)\r\n- [Installation](#installation)\r\n    - [Using nvim-plug](#using-nvim-plug)\r\n    - [Using lazy.nvim](#using-lazynvim)\r\n    - [Using packer.nvim](#using-packernvim)\r\n    - [Using luarocks](#using-luarocks)\r\n- [Usage](#usage)\r\n- [User Commands](#user-commands)\r\n- [Interactive Prompts](#interactive-prompts)\r\n    - [Modified Buffer Prompt](#modified-buffer-prompt)\r\n    - [Terminal Buffer Prompt](#terminal-buffer-prompt)\r\n- [User Autocmds](#user-autocmds)\r\n- [Credits](#credits)\r\n- [Comparison with Existing Plugins](#comparison-with-existing-plugins)\r\n- [Self-Promotion](#self-promotion)\r\n- [License](#license)\r\n\r\n\u003c!-- vim-markdown-toc --\u003e\r\n\r\n## Requirements\r\n\r\n- Neovim \u003e= 0.10.0\r\n\r\n## Installation\r\n\r\n### Using [nvim-plug](https://github.com/wsdjeg/nvim-plug)\r\n\r\n```lua\r\nrequire('plug').add({\r\n    'wsdjeg/bufdel.nvim',\r\n})\r\n```\r\n\r\n### Using [lazy.nvim](https://github.com/folke/lazy.nvim)\r\n\r\n```lua\r\n{\r\n  'wsdjeg/bufdel.nvim',\r\n  cmd = { 'Bdelete', 'Bwipeout' },\r\n  keys = {\r\n    { '\u003cleader\u003ebd', '\u003ccmd\u003eBdelete\u003ccr\u003e', desc = 'Delete buffer' },\r\n    { '\u003cleader\u003ebD', '\u003ccmd\u003eBdelete!\u003ccr\u003e', desc = 'Force delete buffer' },\r\n    { '\u003cleader\u003ebw', '\u003ccmd\u003eBwipeout\u003ccr\u003e', desc = 'Wipeout buffer' },\r\n  },\r\n}\r\n```\r\n\r\n### Using [packer.nvim](https://github.com/wbthomason/packer.nvim)\r\n\r\n```lua\r\nuse('wsdjeg/bufdel.nvim')\r\n```\r\n\r\n### Using luarocks\r\n\r\n```\r\nluarocks install bufdel.nvim\r\n```\r\n\r\n## Usage\r\n\r\nThis plugin exposes a core `delete` function, which accepts two parameters: `buffers` and `opt`.\r\n\r\nThe buffers parameter specifies which buffers should be deleted. It supports multiple forms:\r\n\r\n- A single integer (buffer number), `0` for current buffer.\r\n- A string: it is first resolved to a buffer number using `bufnr(str)`.  \r\n  If a valid buffer number is returned, that buffer is deleted.  \r\n  Otherwise, the string is treated as a Vim regular expression and matched against buffer names.\r\n- A table of integers or strings (each string follows the same resolution rule as above)\r\n- A function, used to filter `vim.api.nvim_list_bufs()`. The function receives a buffer number as its argument and must return a boolean indicating whether the buffer should be deleted.\r\n\r\nThe `opt` parameter is a table used to control the deletion behavior. Supported keys include:\r\n\r\n- `wipe`: whether to wipe the buffer (`bwipeout`) instead of deleting it (`bdelete`)\r\n- `force`: force deletion even if the buffer is modified\r\n- `ignore_user_events`: skip triggering `User BufDelPre` and `User BufDelPost` events\r\n- `switch`: specify which buffer to switch to after deletion\r\n\r\n**Default Behavior:**\r\n\r\nThe Lua API and user commands have different defaults for `switch`:\r\n\r\n| Context                  | Default `switch` | Behavior                            |\r\n| ------------------------ | ---------------- | ----------------------------------- |\r\n| Lua API `delete()`       | `nil`            | Let Neovim decide                   |\r\n| `:Bdelete` / `:Bwipeout` | `'lastused'`     | Switch to most recently used buffer |\r\n\r\nExamples:\r\n\r\n1. Delete a specific buffer\r\n\r\n   Delete a single buffer by providing its buffer number.  \r\n   This is useful when you already know exactly which buffer should be removed.\r\n\r\n   ```lua\r\n   require('bufdel').delete(2, { wipe = true })\r\n   ```\r\n\r\n   - The first argument is the buffer number to delete\r\n   - The buffer must be valid\r\n   - If `wipe = true`, the buffer is wiped (`:bwipeout`)\r\n   - Otherwise, the buffer is deleted (`:bdelete`)\r\n\r\n2. Delete multiple buffers\r\n\r\n   Delete multiple buffers at once by passing a list of buffer numbers.\r\n\r\n   ```lua\r\n   require('bufdel').delete({ 2, 3, 5 }, { wipe = true })\r\n   ```\r\n\r\n   - Each item in the list must be a valid buffer number\r\n   - Invalid or already-deleted buffers are ignored\r\n   - Buffers are deleted in sequence\r\n   - This is useful for batch-cleaning buffers\r\n\r\n3. Delete buffers using a filter function\r\n\r\n   Delete buffers dynamically by providing a filter function.  \r\n   The function is called for each existing buffer and should return true\r\n   if the buffer should be deleted.\r\n\r\n   ```lua\r\n   -- delete other saved buffers\r\n   require('bufdel').delete(function(buf)\r\n       return not vim.bo[buf].modified\r\n           and vim.bo[buf].buflisted\r\n           and buf ~= vim.api.nvim_get_current_buf()\r\n   end, { wipe = true })\r\n   ```\r\n\r\n   - The filter function receives a buffer number\r\n   - Return `true` to mark the buffer for deletion\r\n   - Return `false` or `nil` to keep the buffer\r\n   - This allows conditional deletion based on buffer state\r\n\r\n4. Delete buffers whose names match a regular expression:\r\n\r\n   ```lua\r\n   require('bufdel').delete('.txt$', { wipe = true })\r\n   ```\r\n\r\n   - The buffer name is matched against a Vim regular expression\r\n   - Only buffers whose names satisfy the pattern will be deleted\r\n   - This is useful for cleaning up temporary or generated files\r\n\r\n5. Specify the buffer to switch to after deletion\r\n\r\n   By default, bufdel.nvim lets Neovim decide which buffer to display after a buffer is deleted.  \r\n   You can override this behavior using the switch option to explicitly control which buffer to switch to after deletion.\r\n\r\n   Use a function to customize the switch logic (recommended)\r\n\r\n   ```lua\r\n   require('bufdel').delete(function(buf)\r\n       return not vim.bo[buf].modified and vim.bo[buf].buflisted\r\n   end, {\r\n       wipe = true,\r\n       switch = function(deleted_buf)\r\n           -- Return a valid buffer number\r\n           return vim.fn.bufnr('#') -- switch to the alternate buffer\r\n       end,\r\n   })\r\n   ```\r\n\r\n   When switch is a function:\r\n\r\n   - It receives the deleted buffer number (bufnr)\r\n   - It must return a target bufnr\r\n   - If the returned buffer is invalid, the switch is ignored\r\n\r\n   Use built-in switch strategies\r\n\r\n   ```lua\r\n   require('bufdel').delete(filter, {\r\n       wipe = true,\r\n       switch = 'alt', -- alternate buffer (#)\r\n   })\r\n   ```\r\n\r\n   Supported built-in values:\r\n\r\n   - \"alt\" – alternate buffer (#)\r\n   - \"current\" – keep the current buffer\r\n   - \"lastused\" - the last used buffer\r\n   - \"next\" – next buffer\r\n   - \"prev\" – previous buffer\r\n\r\n   Specify a buffer number directly\r\n\r\n   ```lua\r\n   require('bufdel').delete(filter, {\r\n       wipe = true,\r\n       switch = 3, -- switch to bufnr = 3\r\n   })\r\n   ```\r\n\r\n## User Commands\r\n\r\nbufdel.nvim provides two user commands `:Bdelete` and `:Bwipeout`, which work the same as `:bdelete` and `:bwipeout`,\r\nbut these commands preserve the window layout.\r\n\r\n| Command               | Description                     |\r\n| --------------------- | ------------------------------- |\r\n| `:Bdelete [buf...]`   | Delete buffer(s)                |\r\n| `:Bdelete! [buf...]`  | Force delete (discard changes)  |\r\n| `:Bwipeout [buf...]`  | Wipe buffer(s) completely       |\r\n| `:Bwipeout! [buf...]` | Force wipeout (discard changes) |\r\n\r\nExamples:\r\n\r\n1. Delete the current buffer\r\n   ```\r\n   :Bdelete\r\n   ```\r\n2. Delete a specific buffer by buffer number\r\n   ```\r\n   :Bdelete 3\r\n   ```\r\n3. Delete multiple buffers\r\n   ```\r\n   :Bdelete 2 5 7\r\n   ```\r\n4. Delete a range of buffers\r\n   ```\r\n   :3,6Bdelete\r\n   ```\r\n5. Force delete without saving\r\n   ```\r\n   :Bdelete!\r\n   ```\r\n\r\n**Features:**\r\n\r\n- `\u003cTab\u003e` completion for buffer names\r\n- `!` bang modifier to force deletion\r\n- Range support (`:3,6Bdelete`)\r\n- Multiple buffer arguments\r\n\r\n\u003e **Note:**\r\n\u003e Because of limitations in Vim's Ex command parsing,\r\n\u003e buffer names that consist of digits only cannot be used with `:Bdelete \u003cbufname\u003e`.\r\n\u003e It is the same behavior as `:bdelete` and `:bwipeout`.\r\n\u003e In this case, please use the buffer number instead:\r\n\u003e\r\n\u003e ```\r\n\u003e :Bdelete \u003cbufnr\u003e\r\n\u003e ```\r\n\r\n## Interactive Prompts\r\n\r\nWhen deleting a buffer without `force=true` (or without `!` in commands), bufdel.nvim shows interactive prompts in certain situations:\r\n\r\n### Modified Buffer Prompt\r\n\r\nWhen attempting to delete a buffer with unsaved changes:\r\n\r\n```\r\nsave changes to \"filename\"?  Yes/No/Cancel\r\n```\r\n\r\n- Press `y` (Yes): Save changes and delete the buffer\r\n- Press `n` (No): Discard changes and force delete\r\n- Press any other key: Cancel the deletion\r\n\r\n### Terminal Buffer Prompt\r\n\r\nWhen attempting to delete a terminal buffer with a running job:\r\n\r\n```\r\nTerminal buffer N is still running, killed?  Yes/No\r\n```\r\n\r\n- Press `y` (Yes): Kill the terminal job and delete the buffer\r\n- Press any other key: Keep the terminal running (deletion cancelled)\r\n\r\n## User Autocmds\r\n\r\nbufdel.nvim triggers two user autocmds when deleting a buffer: `User BufDelPre` and `User BufDelPost`.\r\nHere is an example to handle these events:\r\n\r\n```lua\r\nlocal mygroup = vim.api.nvim_create_augroup(\"bufdel_custom\", { clear = true })\r\nvim.api.nvim_create_autocmd({ \"User\" }, {\r\n\tgroup = mygroup,\r\n\tpattern = \"BufDelPre\",\r\n\tcallback = function(ev)\r\n        --- the deleted buffer number is saved in ev.data.buf\r\n    end,\r\n})\r\nvim.api.nvim_create_autocmd({ \"User\" }, {\r\n\tgroup = mygroup,\r\n\tpattern = \"BufDelPost\",\r\n\tcallback = function(ev)\r\n        --- the deleted buffer number is saved in ev.data.buf\r\n    end,\r\n})\r\n```\r\n\r\nThe `User BufDelPost` event will not be triggered if failed to delete the buffer.\r\n\r\n## Credits\r\n\r\n- [bufdelete.nvim](https://github.com/famiu/bufdelete.nvim)\r\n\r\nThe core logic of bufdel.nvim is derived from **bufdelete.nvim**.\r\n\r\n## Comparison with Existing Plugins\r\n\r\nBelow is a minimal comparison of bufdel.nvim and several other buffer-deletion plugins\r\nbased on the features the author personally uses:\r\n\r\n| Feature / Plugin          | bufdel.nvim | [bufdelete.nvim](https://github.com/famiu/bufdelete.nvim) | [nvim-bufdel](https://github.com/ojroques/nvim-bufdel) | [snacks.bufdelete](https://github.com/folke/snacks.nvim/blob/main/lua/snacks/bufdelete.lua) | [mini.bufremove](https://github.com/nvim-mini/mini.nvim/blob/main/lua/mini/bufremove.lua) |\r\n| ------------------------- | ----------- | --------------------------------------------------------- | ------------------------------------------------------ | ------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |\r\n| Preserve window layout    | ✓           | ✓                                                         | ✓                                                      | ✓                                                                                           | ✓                                                                                         |\r\n| Delete by bufnr           | ✓           | ✓                                                         | ✓                                                      | ✓                                                                                           | ✓                                                                                         |\r\n| Delete by bufname         | ✓           | ✓                                                         | ✓                                                      | ✓                                                                                           | ✗                                                                                         |\r\n| User Command              | ✓           | ✓                                                         | ✓                                                      | ✗                                                                                           | ✗                                                                                         |\r\n| Lua filter function       | ✓           | ✗                                                         | ✗                                                      | ✓                                                                                           | ✗                                                                                         |\r\n| Regex buffer matching     | ✓           | ✗                                                         | ✗                                                      | ✗                                                                                           | ✗                                                                                         |\r\n| Post-delete buffer switch | ✓           | ✓                                                         | ✓                                                      | ✗                                                                                           | ✗                                                                                         |\r\n| User autocmd hooks        | ✓           | ✓                                                         | ✗                                                      | ✗                                                                                           | ✗                                                                                         |\r\n\r\nSome plugins are actively maintained. For a more detailed comparison, you're encouraged to\r\ntry them and see which best fits your setup.  \r\nIf you notice any inaccuracies or mistakes in the comparison, please feel free to open an issue.\r\n\r\n## Self-Promotion\r\n\r\nLike this plugin? Star the repository on\r\n[GitHub](https://github.com/wsdjeg/bufdel.nvim).\r\n\r\nLove this plugin? Follow [me](https://wsdjeg.net/) on\r\n[GitHub](https://github.com/wsdjeg) or [Twitter](https://x.com/EricWongDEV).\r\n\r\n## License\r\n\r\nThis project is licensed under the GPL-3.0 License.\r\n","funding_links":[],"categories":["Split and Window","Buffers"],"sub_categories":["Assembly"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsdjeg%2Fbufdel.nvim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwsdjeg%2Fbufdel.nvim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwsdjeg%2Fbufdel.nvim/lists"}