Skip to content
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

Add key binding for clear saved buffers #830

Merged
merged 1 commit into from Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions autoload/SpaceVim/api/vim/buffer.vim
Expand Up @@ -40,6 +40,18 @@ function! s:self.listed_buffers() abort
return filter(range(1, bufnr('$')), 'buflisted(v:val)')
endfunction


function! s:self.filter_do(expr) abort
let buffers = range(1, bufnr('$'))
for f_expr in a:expr.expr
let buffers = filter(buffers, f_expr)
endfor
for b in buffers
exe printf(a:expr.do, b)
endfor
endfunction


fu! SpaceVim#api#vim#buffer#get() abort
return deepcopy(s:self)
endf
1 change: 1 addition & 0 deletions autoload/SpaceVim/layers/default.vim
Expand Up @@ -124,6 +124,7 @@ function! SpaceVim#layers#default#config() abort
\ 'call SpaceVim#mapping#kill_visible_buffer_choosewin()',
\ 'kill-this-buffer', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', '<C-d>'], 'call SpaceVim#mapping#clearBuffers()', 'kill-other-buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 'c'], 'call SpaceVim#mapping#clear_saved_buffers()', 'clear all saved buffers', 1)
call SpaceVim#mapping#space#def('nnoremap', ['b', 'e'], 'call call('
\ . string(s:_function('s:safe_erase_buffer')) . ', [])',
\ 'safe-erase-buffer', 1)
Expand Down
18 changes: 18 additions & 0 deletions autoload/SpaceVim/mapping.vim
@@ -1,4 +1,8 @@
scriptencoding utf-8

let s:BUFFER = SpaceVim#api#import('vim#buffer')


let g:unite_source_menu_menus =
\ get(g:,'unite_source_menu_menus',{})
let g:unite_source_menu_menus.CustomKeyMaps = {'description':
Expand Down Expand Up @@ -200,4 +204,18 @@ function! SpaceVim#mapping#menu(desc, key, cmd) abort
\ a:cmd])
endfunction

function! SpaceVim#mapping#clear_saved_buffers()
call s:BUFFER.filter_do(
\ {
\ 'expr' : [
\ 'buflisted(v:val)',
\ 'index(tabpagebuflist(), v:val) == -1',
\ 'getbufvar(v:val, "&mod") == 0',
\ ],
\ 'do' : 'bd %d'
\ }
\ )
endfunction


" vim:set et sw=2 cc=80: