[转载]HOWTO 使用 vim 的 minibuf 来切换缓冲区
转载自:http://linux.bloghome.cn/posts/114.html
1. 安装到 http://vim.sourceforge.net/scripts/script.php?script_id=159
将该文件复制到 plugin 目录中即可。
2. 配置
在配置文件 .vimrc 中加入:
"
"minibuf plugin
"
let g:miniBufExplMapWindowNavVim = 1 "Ctrl-<hjkl> to move to window
let g:miniBufExplTabWrap = 1 " make tabs show complete (no broken on two lines)
这样就可以使用 minibuf 了,而且设定 Ctrl-h/j/k/l 在各个窗口中切换,很方便。
使用提示:
1. minibuf 占用的就是一个窗口,你可以用 Ctrl-k 切换到其上,然后按 <tab> 循环选择 buffer,
按 <enter> 则激活该 buffer,按 d 则删除该 buffer 。
2. 每个 buffer 名称前都有个数字,那是 buffer 的编号,因此,可以输入 :b <buffer编号> 来快速切换。
先自声明,本人是个懒种,因此设定了几个快捷键:
<F1> 切换至前一缓冲区
<F2> 切换至后一缓冲区
<F3> 保存缓冲区(:update 罗)
<F4> 关闭缓冲区(:bd,或 :bdelete,删除缓冲区)
脚本如下:
nnoremap <F1> :call MyCyclebuffer(0)<CR>
nnoremap <Leader>1 :call MyCyclebuffer(0)<CR>
inoremap <F1> <ESC>:call MyCyclebuffer(0)<CR>
nnoremap <F2> :call MyCyclebuffer(1)<CR>
nnoremap <Leader>2 :call MyCyclebuffer(1)<CR>
inoremap <F2> <ESC>:call MyCyclebuffer(1)<CR>
" Cycle Through buffers
" from MiniBufExplorer, modified by DJW
function! MyCyclebuffer(forward)
" Change buffer (keeping track of before and after buffers)
let l:origBuf = bufnr(''%'')
if (a:forward == 1)
bn!
else
bp!
endif
let l:curBuf = bufnr(''%'')
" Skip any non-modifiable buffers, but don''t cycle forever
" This should stop us from stopping in any of the [Explorers]
while getbufvar(l:curBuf, ''&modifiable'') == 0 && l:origBuf != l:curBuf
if (a:forward == 1)
bn!
else
bp!
endif
let l:curBuf = bufnr(''%'')
endwhile
endfunction
" <F4> delete buffer
nnoremap <F4> :bd<CR>
nnoremap <Leader>4 :bd<CR>
inoremap <F4> <ESC>:bd<CR>
" <F3> or Ctrl-S update buffer
nnoremap <C-S> :update<CR>
inoremap <C-S> <C-O>:update<CR>
vnoremap <C-S> <C-C>:update<CR>
nnoremap <F3> :update<CR>
inoremap <F3> <C-O>:update<CR>
nnoremap <Leader>1 :call MyCyclebuffer(0)<CR>
inoremap <F1> <ESC>:call MyCyclebuffer(0)<CR>
nnoremap <F2> :call MyCyclebuffer(1)<CR>
nnoremap <Leader>2 :call MyCyclebuffer(1)<CR>
inoremap <F2> <ESC>:call MyCyclebuffer(1)<CR>
" Cycle Through buffers
" from MiniBufExplorer, modified by DJW
function! MyCyclebuffer(forward)
" Change buffer (keeping track of before and after buffers)
let l:origBuf = bufnr(''%'')
if (a:forward == 1)
bn!
else
bp!
endif
let l:curBuf = bufnr(''%'')
" Skip any non-modifiable buffers, but don''t cycle forever
" This should stop us from stopping in any of the [Explorers]
while getbufvar(l:curBuf, ''&modifiable'') == 0 && l:origBuf != l:curBuf
if (a:forward == 1)
bn!
else
bp!
endif
let l:curBuf = bufnr(''%'')
endwhile
endfunction
" <F4> delete buffer
nnoremap <F4> :bd<CR>
nnoremap <Leader>4 :bd<CR>
inoremap <F4> <ESC>:bd<CR>
" <F3> or Ctrl-S update buffer
nnoremap <C-S> :update<CR>
inoremap <C-S> <C-O>:update<CR>
vnoremap <C-S> <C-C>:update<CR>
nnoremap <F3> :update<CR>
inoremap <F3> <C-O>:update<CR>