Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions README

This file was deleted.

30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Copy by [vim-scripts/QuickBuf](http://www.vim.org/scripts/script.php?script_id=1910)

QuickBuf
---
>Vim plugin helps navigate and manipulate buffers

**Brief description:**
>While making the task of browsing and manipulating buffers visual and simple, QuickBuf also offers advanced abilities of dealing with buffers (ex: "unlisted" mode). It's unique among several other buffer managers for creating no dedicated buffer and defining no auto command, thus minimize its interference.

**Usage:**
>+ Press the assigned hotkey to activate QuickBuf (default <F4>). It brings out a list of buffers that you can browse and give commands on! Some indicators in the list:
- * : the buffer being opened in the active window
- = : a buffer being opened in a window, but not active
- [+] : modifed buffer
>+ Use j/k \<Up>/\<Down> J/K goto prev+/next+ line, g/G goto first/last line
>+ Press a key to give a command to the currently selected buffer
- d/D : del/!delete buffer
- w/W : wipe/!wipe out buffer
- s : open buffer in a new horizontally split window
- v : open buffer in a new vertically split window
- f : open buffer
- e : quickly switch buffer in current window
- <enter/space> : open buffer and leave QuickBuf; if the buffer is already opened in a window, switch to that window.
>+ d, w, and <enter> operations may fail, You can use D, W force operation
>+ Instead of moving the selection bar around to select a buffer, you can use a number to specify a buffer. For example: '2d' will delete the second buffer in the list. Try '3f', '1w', '1!w' or '1W'
>+ Use 'l' key to toggle between LISTED and UNLISTED mode. Which mode QuickBuf enter first depends on the active buffer. While in UNLISTED mode, 'unlisted' buffers (the buffers you have deleted) are showed. Also:
- [+] indicates a loaded buffer
- 'd' command makes the selected buffer 'listed' again
>+ Press \<esc\>/q key to leave QuickBuf

74 changes: 57 additions & 17 deletions plugin/qbuf.vim
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
"=====================
" QuickBuf
" version 1.7
"=====================
if v:version < 700
finish
endif

if !exists("g:qb_hotkey") || g:qb_hotkey == ""
let g:qb_hotkey = "<F4>"
endif
exe "nnoremap <unique>" g:qb_hotkey " :cal <SID>init(1)<cr>:cal SBRun()<cr>"
exe "cnoremap <unique>" g:qb_hotkey "<Esc>"

if exists("g:qb_loaded") && g:qb_loaded
finish
endif
let g:qb_loaded = 1

let s:action2cmd = {"z": 'call <SID>switchbuf(#,"")', "!z": 'call <SID>switchbuf(#,"!")',
\"u": "hid b #|let s:cursel = (s:cursel+1) % s:blen",
if !exists("g:qb_hotkey") || g:qb_hotkey == ""
let g:qb_hotkey = "<F4>"
endif
exe "nnoremap <unique>" g:qb_hotkey " :cal <SID>init(1)<cr>:cal SBRun()<cr>"

let s:action2cmd = {
\"z": 'call <SID>switchbuf(#,"")', "!z": 'call <SID>switchbuf(#,"!")',
\"f": 'call <SID>switchbuf(#,"")', "!f": 'call <SID>switchbuf(#,"!")',
\"F": 'call <SID>switchbuf(#,"!")',
\"s": "sb #",
\"v": "vert sb #",
\"e": "hid b #|let s:cursel = (s:cursel+1) % s:blen",
\"d": 'call <SID>qbufdcmd(#,"")', "!d": 'call <SID>qbufdcmd(#,"!")',
\"D": 'call <SID>qbufdcmd(#,"!")',
\"w": "bw #", "!w": "bw! #",
\"W": "bw! #",
\"l": "let s:unlisted = 1 - s:unlisted",
\"c": 'call <SID>closewindow(#,"")'}
\"c": 'call <SID>closewindow(#,"")'
\}

function s:rebuild()
redir @y | silent ls! | redir END
Expand Down Expand Up @@ -62,6 +72,13 @@ function SBRun()
if !exists("s:cursel") || (s:cursel >= s:blen) || (s:cursel < 0)
let s:cursel = s:blen-1
endif
if !exists("s:old_cursel")
let s:old_cursel = s:cursel
endif
if !exists("s:hasMore")
let s:hasMore = &more
endif
set nomore

if s:blen < 1
echoh WarningMsg | echo "No" s:unlisted ? "unlisted" : "listed" "buffer!" | echoh None
Expand All @@ -83,36 +100,55 @@ function SBRun()
if s:unlisted
echoh None
endif
if l:pkey =~ "j$"
if l:pkey =~# "j$"
let s:cursel = (s:cursel+1) % s:blen
elseif l:pkey =~ "k$"
elseif l:pkey =~# "k$"
if s:cursel == 0
let s:cursel = s:blen - 1
else
let s:cursel -= 1
endif
elseif l:pkey =~# "J$"
let l:cl = s:cursel+5
let s:cursel = l:cl > s:blen ? s:blen : l:cl
elseif l:pkey =~# "K$"
let l:cl = s:cursel-5
let s:cursel = l:cl < 0 ? 0 : l:cl
elseif l:pkey =~# "G$"
let s:cursel = s:blen
elseif l:pkey =~# "g$"
let s:cursel = 0
elseif s:update_buf(l:pkey)
call s:init(0)
if s:hasMore
set more
endif
return
endif
call s:setcmdh(s:blen+1)
endfunc

let s:klist = ["j","J","k","K","g","G","f","F","e","d","D","w","W","l","s","v","c","q"]
function s:init(onStart)
if a:onStart
set nolazyredraw
let s:unlisted = 1 - getbufvar("%", "&buflisted")
let s:cursorbg = synIDattr(hlID("Cursor"),"bg")
let s:cursorfg = synIDattr(hlID("Cursor"),"fg")
let s:cmdh = &cmdheight
hi Cursor guibg=NONE guifg=NONE
"hi Cursor guibg=NONE guifg=NONE

let s:klist = ["j", "k", "u", "d", "w", "l", "s", "c"]
for l:key in s:klist
exe "cnoremap ".l:key." ".l:key."<cr>:cal SBRun()<cr>"
if l:key == "q"
exe "cnoremap ".l:key." :cal s:init(0)<cr>:echo''<cr>"
else
exe "cnoremap ".l:key." ".l:key."<cr>:cal SBRun()<cr>"
endif
endfor
cmap <up> k
cmap <down> j
cnoremap <space> <cr>
exe "cnoremap <c-c> :cal s:init(0)<cr>:echo''<cr>"

call s:rebuild()
let s:cursel = match(s:buflist, '^\d*\*')
Expand All @@ -124,7 +160,9 @@ function s:init(onStart)
endfor
cunmap <up>
cunmap <down>
exe "hi Cursor guibg=" . s:cursorbg . " guifg=".((s:cursorfg == "") ? "NONE" : s:cursorfg)
cunmap <space>
cunmap <c-c>
"exe "hi Cursor guibg=" . s:cursorbg . " guifg=".((s:cursorfg == "") ? "NONE" : s:cursorfg)
endif
endfunc

Expand Down Expand Up @@ -160,8 +198,10 @@ endfunc

function s:setcmdh(height)
if a:height > &lines - winnr('$') * (&winminheight+1) - 1
call s:init(0)
echo "\r"|echoerr "QBuf E1: No room to display buffer list"
"call s:init(0)
"exe "set cmdheight=".s:blen
exe "set cmdheight=".1
"echo "\r"|echoerr "QBuf E1: No room to display buffer list"
else
exe "set cmdheight=".a:height
endif
Expand Down