diff --git a/README b/README deleted file mode 100644 index cccf9ca..0000000 --- a/README +++ /dev/null @@ -1,30 +0,0 @@ -This is a mirror of http://www.vim.org/scripts/script.php?script_id=1910 - -QuickBuf -Vim plugin helps navigate and manipulate buffers -Maintainer: palnart - -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. - -Give it a try and you may find it all you need to work with Vim's buffers! -Any bugs or suggestions, please mail to: palnart@gmail.com - -Usage: -+ Press the assigned hotkey to activate QuickBuf (default ). 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 k/j or / keys to select the buffer. -+ Press a key to give a command to the currently selected buffer - - d : delete buffer - - w : wipe out buffer - - s : open buffer in a new horizontally split window - - u : open buffer - - : open buffer and leave QuickBuf; if the buffer is already opened in a window, switch to that window. -+ d, w, and operations may fail (ex: delete a modified buffer), QuickBuf will inform you so that you can force them by preceding the above characters with an exclamation mark ('!'). Ex: !d, !w, ! -+ 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 '3', '1w', '1!w' -+ 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 key to leave QuickBuf diff --git a/README.md b/README.md new file mode 100644 index 0000000..6d8426f --- /dev/null +++ b/README.md @@ -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 ). 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 \/\ 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 + - : open buffer and leave QuickBuf; if the buffer is already opened in a window, switch to that window. +>+ d, w, and 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 \/q key to leave QuickBuf + diff --git a/plugin/qbuf.vim b/plugin/qbuf.vim index db5678f..44aae34 100644 --- a/plugin/qbuf.vim +++ b/plugin/qbuf.vim @@ -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 = "" -endif -exe "nnoremap " g:qb_hotkey " :cal init(1):cal SBRun()" -exe "cnoremap " g:qb_hotkey "" - if exists("g:qb_loaded") && g:qb_loaded finish endif let g:qb_loaded = 1 -let s:action2cmd = {"z": 'call switchbuf(#,"")', "!z": 'call switchbuf(#,"!")', - \"u": "hid b #|let s:cursel = (s:cursel+1) % s:blen", +if !exists("g:qb_hotkey") || g:qb_hotkey == "" + let g:qb_hotkey = "" +endif +exe "nnoremap " g:qb_hotkey " :cal init(1):cal SBRun()" + +let s:action2cmd = { + \"z": 'call switchbuf(#,"")', "!z": 'call switchbuf(#,"!")', + \"f": 'call switchbuf(#,"")', "!f": 'call switchbuf(#,"!")', + \"F": 'call switchbuf(#,"!")', \"s": "sb #", + \"v": "vert sb #", + \"e": "hid b #|let s:cursel = (s:cursel+1) % s:blen", \"d": 'call qbufdcmd(#,"")', "!d": 'call qbufdcmd(#,"!")', + \"D": 'call qbufdcmd(#,"!")', \"w": "bw #", "!w": "bw! #", + \"W": "bw! #", \"l": "let s:unlisted = 1 - s:unlisted", - \"c": 'call closewindow(#,"")'} + \"c": 'call closewindow(#,"")' + \} function s:rebuild() redir @y | silent ls! | redir END @@ -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 @@ -83,21 +100,35 @@ 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 @@ -105,14 +136,19 @@ function s:init(onStart) 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.":cal SBRun()" + if l:key == "q" + exe "cnoremap ".l:key." :cal s:init(0):echo''" + else + exe "cnoremap ".l:key." ".l:key.":cal SBRun()" + endif endfor cmap k cmap j + cnoremap + exe "cnoremap :cal s:init(0):echo''" call s:rebuild() let s:cursel = match(s:buflist, '^\d*\*') @@ -124,7 +160,9 @@ function s:init(onStart) endfor cunmap cunmap - exe "hi Cursor guibg=" . s:cursorbg . " guifg=".((s:cursorfg == "") ? "NONE" : s:cursorfg) + cunmap + cunmap + "exe "hi Cursor guibg=" . s:cursorbg . " guifg=".((s:cursorfg == "") ? "NONE" : s:cursorfg) endif endfunc @@ -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