Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Last active November 22, 2017 13:52
Show Gist options
  • Select an option

  • Save rainerborene/8074898 to your computer and use it in GitHub Desktop.

Select an option

Save rainerborene/8074898 to your computer and use it in GitHub Desktop.
Close buffer via <C-@> using CtrlP
let g:ctrlp_buffer_func = { 'enter': 'CtrlPMappings' }
function! CtrlPMappings()
nnoremap <buffer> <silent> <C-@> :call <sid>DeleteBuffer()<cr>
endfunction
function! s:DeleteBuffer()
let path = fnamemodify(getline('.')[2:], ':p')
let bufn = matchstr(path, '\v\d+\ze\*No Name')
exec "bd" bufn ==# "" ? path : bufn
exec "norm \<F5>"
endfunction
@korjavin

Copy link
Copy Markdown

Nice!

@kulbida

kulbida commented Jul 7, 2015

Copy link
Copy Markdown

Awesome!

@nooncat

nooncat commented Dec 29, 2015

Copy link
Copy Markdown

cool!

@varepsilon

Copy link
Copy Markdown

Seems like this approach doesn't work when the filename is long and CtrlP replaces part of its name by "..." Any ideas how to modify the script to handle this case as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment