├── README.md ├── doc └── sbd.txt └── plugin └── sbd.vim /README.md: -------------------------------------------------------------------------------- 1 | # NOTE 2 | 3 | **This is a mirror of github.com/orftz/sbd.vim. That github account appears to have been deleted.** 4 | 5 | sbd.vim 6 | ======= 7 | 8 | Flattr this 9 | 10 | **Close buffers smartly**. 11 | 12 | Because Vim's vanilla buffer closing/deletion becomes painful as soon as you start working with multiple buffers and windows. 13 | 14 | *sbd* allows you to close buffers while leaving your window layout intact. As a bonus, deleting a special buffer (e.g. *quickfix*, *help*, *directory*, *scratch*, etc) will automatically close the window holding it. Making these special buffers easier to deal with. 15 | 16 | 17 | ## Installation 18 | 19 | If you don't have a preferred installation method, I recommend installing [pathogen](https://github.com/tpope/vim-pathogen), and run: 20 | 21 | cd ~/.vim/bundle 22 | git clone git://github.com/orftz/sbd.vim.git 23 | 24 | Then, add the following to your *vimrc*, as-is or tweaked to your taste: 25 | 26 | nnoremap bd :Sbd 27 | nnoremap bdm :Sbdm 28 | 29 | `:Sbd` closes the buffer normally, while `:Sbdm` closes the buffer disregarding if it has unsaved changes or not. 30 | 31 | Once help tags have been generated, you can view the manual with `:help sbd.vim`. 32 | 33 | Enjoy. 34 | 35 | 36 | ## Changelog 37 | 38 | **1.1.1** — NOTE: I may have screwed up a merge in **1.1.0**. If you're running in such a problem, simply re-install the plugin. Sorry for the fuss. 39 | 40 | **1.1.0** — DeleteBuffer() modes 41 | 42 | * `modeNormal` used via `:Sbd` does the normal thing 43 | * `modeCloseModified` used via `:Sbdm` closes the buffer even if it's modified (has unsaved changes) 44 | 45 | **1.0.3** — Better README 46 | 47 | **1.0.2** — Flattr button 48 | 49 | **1.0.1** — Documentation and README clarification 50 | 51 | **1.0.0** — Initial stable release 52 | 53 | 54 | ## License ([ISC](https://en.wikipedia.org/wiki/ISC_license)) 55 | 56 | © 2012 Orphée Lafond-Lummis 57 | 58 | Permission to use, copy, modify, and/or distribute this software for any 59 | purpose with or without fee is hereby granted, provided that the above 60 | copyright notice and this permission notice appear in all copies. 61 | 62 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 63 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 64 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 65 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 66 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 67 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 68 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 69 | -------------------------------------------------------------------------------- /doc/sbd.txt: -------------------------------------------------------------------------------- 1 | *sbd.vim* Smart Buffer Delete 2 | 3 | ============================================================================== 4 | CONTENTS *sbd-contents* 5 | 6 | 1. Intro .......................... |sbdIntro| 7 | 2. Usage .......................... |sbdUsage| 8 | 3. Configuration .................. |sbdConfig| 9 | 3.1 sbd_delete_anyway ......... |sbd_delete_anyway| 10 | 3.2 sbd_close_special ........ |sbd_close_special| 11 | 4. License ........................ |sbdLicense| 12 | 5. Bugs ........................... |sbdBugs| 13 | 6. Contributing ................... |sbdContributing| 14 | 7. Changelog ...................... |sbdChangelog| 15 | 8. Credits ........................ |sbdCredits| 16 | 17 | 18 | ============================================================================== 19 | 1. Intro *sbdIntro* 20 | 21 | Vim's vanilla buffer closing/deletion becomes painful as soon as you 22 | start working with multiple buffers and windows. 23 | 24 | sbd allows you to close buffers while leaving your window layout intact. As 25 | a bonus, deleting a special buffer (e.g. |quickfix|, |help|, |directory|, 26 | |scratch|, etc) will automatically close the window holding it. Making these 27 | special buffers easier to deal with. 28 | 29 | 30 | ============================================================================== 31 | 2. Usage *sbdUsage* 32 | 33 | Add the following to your |vimrc|, as-is or tweaked to your taste: > 34 | 35 | nnoremap bd :Sbd 36 | nnoremap bdm :Sbdm 37 | 38 | `:Sbd` closes the buffer normally, while `:Sbdm` closes the buffer 39 | disregarding if it has unsaved changes or not. 40 | 41 | 42 | ============================================================================== 43 | 3. Configuration *sbdConfig* 44 | 45 | You can tweak the behavior of sbd by setting a few variables in your |vimrc| 46 | file. For example: > 47 | 48 | let g:sbd_delete_anyway=1 49 | let g:sbd_close_special=0 50 | 51 | ------------------------------------------------------------------------------ 52 | 3.1 g:sbd_delete_anyway *sbd_delete_anyway* 53 | 54 | Delete buffer even if containing unsaved changes. 55 | 56 | Default: 0 (off) 57 | 58 | ------------------------------------------------------------------------------ 59 | 3.2 g:sbd_close_special *sbd_close_special* 60 | 61 | Set the vertical height of the Gunclose special buffer's window toodo preview. 62 | 63 | Default: 1 (on) 64 | 65 | 66 | ============================================================================== 67 | 4. License *sbdLicense* 68 | 69 | ISC license https://en.wikipedia.org/wiki/ISC_license > 70 | 71 | © 2012 Orphée Lafond-Lummis 72 | 73 | Permission to use, copy, modify, and/or distribute this software for any 74 | purpose with or without fee is hereby granted, provided that the above 75 | copyright notice and this permission notice appear in all copies. 76 | 77 | THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 78 | WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 79 | MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 80 | ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 81 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 82 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 83 | OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 84 | 85 | 86 | ============================================================================== 87 | 5. Bugs *sbdBugs* 88 | 89 | If you find a bug please post it on the issue tracker: 90 | 91 | https://github.com/orftz/sbd.vim/issues 92 | 93 | 94 | ============================================================================== 95 | 6. Contributing *sbdContributing* 96 | 97 | Think you can make this plugin better? I love your mindset. Fork it on GitHub 98 | and send a pull request. 99 | 100 | https://github.com/orftz/sbd.vim 101 | 102 | 103 | ============================================================================== 104 | 7. Changelog *sbdChangelog* 105 | 106 | **1.1.1** — NOTE: I may have screwed up a merge in **1.1.0**. If you're 107 | running in such a problem, simply re-install the plugin. Sorry for the fuss. 108 | 109 | **1.1.0** — DeleteBuffer() modes 110 | 111 | * `modeNormal` used via `:Sbd` does the normal thing 112 | * `modeCloseModified` used via `:Sbdm` closes the buffer even if it's modified 113 | 114 | **1.0.3** — Better README 115 | 116 | **1.0.2** — Flattr button 117 | 118 | **1.0.1** — Documentation and README clarification 119 | 120 | **1.0.0** — Initial stable release 121 | 122 | 123 | ============================================================================== 124 | 8. Credits *sbdCredits* 125 | 126 | The code is heavily based on kwbdi.vim, which is itself based on kwbd.vim and 127 | minibufexpl. Many thanks to the contributors of these plugins. 128 | 129 | The doc is based on gundo.vim's. Thanks Steve Losh. 130 | 131 | 132 | ------------------------------------------------------------------------------ 133 | vim:tw=78:fo=tcq2:ai:isk=!-~,^*,^\|,^\":ts=4:ft=help:norl: 134 | -------------------------------------------------------------------------------- /plugin/sbd.vim: -------------------------------------------------------------------------------- 1 | " sbd.vim — Smart Buffer Delete 2 | " 3 | " :help sbd.txt 4 | 5 | if exists('loaded_sbd') 6 | finish 7 | endif 8 | let loaded_sbd = 1 9 | 10 | if !exists('g:sbd_delete_anyway') 11 | let g:sbd_delete_anyway = 0 12 | endif 13 | 14 | if !exists('g:sbd_close_special') 15 | let g:sbd_close_special = 1 16 | endif 17 | 18 | let s:modeNormal = 'n' 19 | let s:modeCloseModified = 'm' 20 | 21 | silent command! -nargs=0 Sbd call DeleteBuffer(s:modeNormal) 22 | silent command! -nargs=0 Sbdm call DeleteBuffer(s:modeCloseModified) 23 | 24 | function DeleteBuffer(mode) 25 | let s:sbdBuffer = bufnr("%") 26 | let s:sbdBufferCount = 0 27 | let s:sbdEmptyBuffer = 0 28 | let s:sbdWindow = winnr() 29 | 30 | if (a:mode != s:modeCloseModified 31 | \ && getbufvar(s:sbdBuffer, '&modified') == 1 32 | \ && g:sbd_delete_anyway == 0) 33 | echom "sbd: save your changes first." 34 | return 35 | endif 36 | 37 | for i in range(1, bufnr('$')) 38 | if (getbufvar(i, '&buflisted') == 1 && getbufvar(i, '&modifiable') == 1) 39 | let s:sbdBufferCount = s:sbdBufferCount + 1 40 | endif 41 | endfor 42 | 43 | windo call s:PreserveWindowLayout() 44 | 45 | if (getbufvar(s:sbdBuffer, '&buflisted') == 1) 46 | execute "bdelete! " . s:sbdBuffer. "" 47 | endif 48 | 49 | " switch to original window 50 | execute "normal! " . s:sbdWindow . "\\" 51 | endfunction 52 | 53 | function s:PreserveWindowLayout() 54 | if (s:sbdBuffer == bufnr("%")) 55 | let prevBuffer = bufnr("#") 56 | 57 | " we're dealing with a special buffer 58 | if (&buftype != "" && g:sbd_close_special == 1) 59 | close 60 | 61 | " switch to a convenient buffer 62 | elseif (s:sbdBufferCount <= 1 && s:sbdEmptyBuffer != 0) 63 | execute "buffer! " . s:sbdEmptyBuffer 64 | elseif (s:sbdBufferCount <= 1 && s:sbdEmptyBuffer == 0) 65 | enew! 66 | let s:sbdEmptyBuffer = bufnr('%') 67 | elseif (prevBuffer > 0 && buflisted(prevBuffer) && prevBuffer != s:sbdBuffer) 68 | buffer! # 69 | else 70 | bprevious! 71 | endif 72 | endif 73 | endfunction 74 | --------------------------------------------------------------------------------