-
Notifications
You must be signed in to change notification settings - Fork 676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Delete Buffer in CtrlPBuf Mode #280
Comments
ctrlp doesn't have this built-in. I'm not going to add it because it's not essential, and you can just be creative with the options. Use something like this in your vimrc, for example: let g:ctrlp_buffer_func = { 'enter': 'MyCtrlPMappings' }
func! MyCtrlPMappings()
nnoremap <buffer> <silent> <c-@> :call <sid>DeleteBuffer()<cr>
endfunc
func! s:DeleteBuffer()
let line = getline('.')
let bufid = line =~ '\[\d\+\*No Name\]$' ? str2nr(matchstr(line, '\d\+'))
\ : fnamemodify(line[2:], ':p')
exec "bd" bufid
exec "norm \<F5>"
endfunc Then pressing |
I might take another stab at this. My extremely limited knowledge of Vimscript and of the source code in ctrlp tripped me up last time. Good to have some example code to go by :) I was aiming for something where you could I'm pretty bad at opening lots of buffers and then having the tedious task of closing the ones I'm no longer using. |
I'm going to respectfully disagree; so what if it's non essential? It sounds like a very useful feature to me: it fits naturally within the use case and looks like it'd be very easy to add. I realize the author is probably worried about bloat but making your users extend your addon through their .vimrc for simple things like this doesn't sound like a good design trade off to me. |
It's partly because there aren't many usable mappings left to use. I'd also have to make something to allow changing the deletion command between |
I'm also interested in this feature. CtrlP has replaced BufExplorer for switching between buffers. The only reason I keep BufExplorer is to wipe buffers. I imagine I'm not alone in this common use case. It would be awesome if I could run |
plus one 👍 for this feature request 😃 (yep, i have read entire thread) |
+1 |
3 similar comments
👍 |
👍 |
+1 |
+1 - I'd also like to avoid installing yet another buffer explorer plugin for this use case. That being said, CtrlP is an awesome plugin, great work! |
@kien the script you provided has been working great, however I have found one issue with it. If I attempt to delete default blank buffers, it seems to trip up. The first buffer showing here: [123*No Name] as show here: If I attempt to delete it using the I am not too hot with Vim script, but if you know a quick and easy fix for this, that would be awesome. I can select the buffer itself and manually :bd it no problem, so not sure what the problem is from the snippet's perspective. |
@amadeus Yeah, the snippet was written before the addition of No Name buffers. I've updated it a bit. |
Thanks, I'll check it out. |
+1 |
2 similar comments
+1 |
+1 |
I'm currently taking this snippet at looking to provide it as a plugin with the @kien doing |
We're doing Hack Day for the next couple of days at work and I'm keen to use that time to add this functionality to ctrlp via an extension in a separate plugin. Some problems I need to solve are:
Here's a work in progress version of the snippet that allows the use of let g:ctrlp_buffer_func = { 'enter': 'CtrlPBDelete' }
function! CtrlPBDelete()
nnoremap <buffer> <silent> <c-@> :call <sid>DeleteMarkedBuffers()<cr>
endfunction
function! s:DeleteMarkedBuffers()
" list all marked buffers
let marked = ctrlp#getmarkedlist()
" the file under the cursor is implicitly marked
if empty(marked)
call add(marked, fnamemodify(ctrlp#getcline(), ':p'))
endif
" call bdelete on all marked buffers
for fname in marked
let bufid = fname =~ '\[\d\+\*No Name\]$' ? str2nr(matchstr(fname, '\d\+'))
\ : fnamemodify(fname[2:], ':p')
exec "silent! bdelete" bufid
endfor
" refresh ctrlp
exec "normal \<F5>"
endfunction I'm sure there are some bugs with it, but I have another day and half to work on this anyway. |
Improved further and turned into a plugin. Pull requests welcomed. https://github.com/d11wtq/ctrlp_bdelete.vim |
Excellent. The plugin works for me! |
Very cool! Thanks for the plugin. Works great! |
+1, please, add it to ctrlp or accept a pull request for it. |
@kien |
@j5shi Thanks for the PR. Just added it to my Vim install on Windows. Working great. |
I searched through the documentation but I couldn't find it anywhere...
I tend to be pretty anal about my buffer management and thought it would be nice to press <c-d> and delete the currently selected buffer in the list (and keep the buffer list open).
Thoughts?
The text was updated successfully, but these errors were encountered: