1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-23 17:50:04 +08:00

feat(buffer): add SPC b ctrl-shift-d to kill buffer by regexp

This commit is contained in:
wsdjeg 2022-02-03 22:46:50 +08:00
parent ee199f05cb
commit 9685aa13d4
5 changed files with 142 additions and 119 deletions

View File

@ -12,6 +12,7 @@ let s:specified_keys = {
\ "\<F1>" : 'F1',
\ "\<F2>" : 'F2',
\ "\<Space>" : 'SPC',
\ "\x80\xfc\<C-b>\<C-d>" : '<C-S-d>',
\ }
function! s:self.nr2name(nr) abort
@ -34,6 +35,13 @@ function! s:self.nr2name(nr) abort
endif
endfunction
function! s:self.char2name(char) abort
if len(a:char) == 1
return self.nr2name(char2nr(a:char))
endif
return get(s:specified_keys, a:char, a:char)
endfunction
function! SpaceVim#api#vim#key#get() abort
return deepcopy(s:self)

View File

@ -129,9 +129,24 @@ function! SpaceVim#mapping#clear_buffers() abort
endfunction
function! SpaceVim#mapping#kill_buffer_expr() abort
let regexp = input('kill buffer by regexp:',
\ '')
if !empty(regexp)
let blisted = filter(range(1, bufnr('$')), 'bufname(v:val) =~ regexp')
for i in blisted
if i != bufnr('%')
try
exe 'bw ' . i
catch
endtry
endif
endfor
noautocmd normal! :
echo printf('killed buffers done(%s)', regexp)
else
noautocmd normal! :
echo 'canceled!'
endif
endfunction
function! SpaceVim#mapping#split_previous_buffer() abort

View File

@ -479,7 +479,7 @@ function! s:wait_for_input() abort " {{{
if inp ==# ' '
let inp = '[SPC]'
else
let inp = s:KEY.nr2name(char2nr(inp))
let inp = s:KEY.char2name(inp)
endif
let fsel = get(s:lmap, inp)
if !empty(fsel)

View File

@ -986,7 +986,7 @@ call SpaceVim#custom#SPC('nnoremap', ['f', 't'], 'echom "hello world"', 'test cu
文本相关的命令 (以 `x` 开头)
| 快捷键 | 功能描述 |
| ------------- | ------------------------------------------------------------------ |
| ---------------- | ------------------------------------------------------------------ |
| `SPC x a #` | 基于分隔符 # 进行文本对齐 |
| `SPC x a %` | 基于分隔符 % 进行文本对齐 |
| `SPC x a &` | 基于分隔符 & 进行文本对齐 |
@ -1002,7 +1002,7 @@ call SpaceVim#custom#SPC('nnoremap', ['f', 't'], 'echom "hello world"', 'test cu
| `SPC x a ;` | 基于分隔符 ; 进行文本对齐 |
| `SPC x a =` | 基于分隔符 = 进行文本对齐 |
| `SPC x a ¦` | 基于分隔符 ¦ 进行文本对齐 |
| `SPC x a |` | 基于分隔符 \| 进行文本对齐 |
| `SPC x a <bar> ` | 基于分隔符 \| 进行文本对齐 |
| `SPC x a SPC` | 基于分隔符 <Space> 进行文本对齐 |
| `SPC x a a` | align region (or guessed section) using default rules (TODO) |
| `SPC x a c` | align current indentation region using default rules (TODO) |
@ -1290,7 +1290,7 @@ SpaceVim 选项 `window_leader` 的值来设为其它按键:
主要包括了缓冲区的切换和删除等操作:
| 快捷键 | 功能描述 |
| --------------- | ------------------------------------------------------------------------------ |
| -------------------- | ------------------------------------------------------------------------------ |
| `SPC <Tab>` | 切换至前一缓冲区,常用于两个缓冲区来回切换 |
| `SPC b .` | 启用缓冲区临时快捷键 |
| `SPC b b` | 通过模糊搜索工具进行缓冲区切换,需要启用一个模糊搜索工具模块 |
@ -1299,8 +1299,8 @@ SpaceVim 选项 `window_leader` 的值来设为其它按键:
| `SPC b D` | 选择一个窗口,并删除其缓冲区 |
| `SPC u SPC b D` | kill a visible buffer and its window using ace-window(TODO) |
| `SPC b c` | 删除其它已保存的缓冲区 |
| `SPC b C-d` | 删除其它所有缓冲区 |
| `SPC b C-D` | kill buffers using a regular expression(TODO) |
| `SPC b Ctrl-d` | 删除其它所有缓冲区 |
| `SPC b Ctrl-Shift-d` | 删除名称匹配指定正则表达式的缓冲区 |
| `SPC b e` | 清除当前缓冲区内容,需要手动确认 |
| `SPC b h` | 打开欢迎界面, 等同于快捷键 `SPC a s` |
| `SPC b n` | 切换至下一个缓冲区,排除特殊插件的缓冲区 |
@ -1531,7 +1531,7 @@ endfunction
#### 常用按键绑定
| 快捷键 | 功能描述 |
| --------------- | ----------------------------------------- |
| --------- | ------------------ |
| `SPC r l` | 恢复上一次搜索历史 |
#### 在当前文件中进行搜索

View File

@ -1380,7 +1380,7 @@ Windows manipulation commands (start with `w`):
Buffer manipulation commands (start with `b`):
| Key Bindings | Descriptions |
| --------------- | ------------------------------------------------------------------------------ |
| -------------------- | ------------------------------------------------------------------------------ |
| `SPC <Tab>` | switch to alternate buffer in the current window (switch back and forth) |
| `SPC b .` | buffer transient state |
| `SPC b b` | switch to a buffer (via denite/unite) |
@ -1389,7 +1389,7 @@ Buffer manipulation commands (start with `b`):
| `SPC b D` | kill a visible buffer using vim-choosewin |
| `SPC u SPC b D` | kill a visible buffer and its window using ace-window(TODO) |
| `SPC b Ctrl-d` | kill other buffers |
| `SPC b Ctrl-D` | kill buffers using a regular expression(TODO) |
| `SPC b Ctrl-Shift-d` | kill buffers using a regular expression |
| `SPC b e` | erase the content of the buffer (ask for confirmation) |
| `SPC b h` | open _SpaceVim_ home buffer |
| `SPC b n` | switch to next buffer avoiding special buffers |