From f8181fa72460c721a55995e0322eabd53f1cc3d4 Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 14 Jul 2010 11:15:31 +0100 Subject: [PATCH] BufExplorer tweaks. Tweak highlighting to make the current and alternate buffers more noticeable and hidden buffers more subtle. Map 0 to search for the active buffer. Map 1-9 to search for matching buffer numbers, selecting unique matches. --- .vim/colors/iain.vim | 11 ++++++----- .vimrc | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 5 deletions(-) diff --git a/.vim/colors/iain.vim b/.vim/colors/iain.vim index 320ade5..ef75180 100644 --- a/.vim/colors/iain.vim +++ b/.vim/colors/iain.vim @@ -347,14 +347,15 @@ if has("gui_running") || &t_Co == 88 || &t_Co == 256 hi link treePartFile treeDirSlash " Fix up BufExplorer stuff. - hi link bufExplorerHelp String - hi link bufExplorerSortBy Statement + hi link bufExplorerHelp Include + hi link bufExplorerSortBy Include hi link bufExplorerMapping Identifier hi link bufExplorerTitle Statement hi link bufExplorerActBuf Directory - hi link bufExplorerAltBuf String - hi link bufExplorerCurBuf Type - hi link bufExplorerUnlBuf Comment + hi link bufExplorerAltBuf Type + hi link bufExplorerCurBuf Statement + hi link bufExplorerHidBuf Comment + hi link bufExplorerUnlBuf String hi link bufExplorerBufNbr Normal endif diff --git a/.vimrc b/.vimrc index 68357f3..b74b7c8 100644 --- a/.vimrc +++ b/.vimrc @@ -1081,6 +1081,44 @@ fun! ToggleCursorLine() "{{{2 endif endfun "}}}2 +" Handle searching in a BufExplorer window. +fun! BufExplorer_Search(n) "{{{2 + if a:n == 0 + let l:re = '^ *\d %' + else + let l:re = "^ *" . a:n + endif + + " Find matching line. + let l:line = search(l:re, 'w') + if ! l:line + return + endif + + if a:n == 0 + return + endif + + " Peek ahead to the next matching line. + let l:next = search(l:re, 'w') + + " Select the buffer if the match is unambiguous. + if l:next == l:line + exe "normal \" + return + endif + + " Go back. + call cursor(l:line, 0) +endfun! "}}}2 + +" Entering a BufExplorer window. +fun! BufExplorer_Map() "{{{2 + for l:n in [ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" ] + exec "nnoremap " . l:n . " :call BufExplorer_Search(" . l:n . ")" + endfor +endfun "}}}2 + if has("windows") se tabline=%!Show_TabLine() se guitablabel=%!Show_GUITabLine() @@ -1102,6 +1140,8 @@ if has("autocmd") au Signs InsertEnter * call Highlight_Signs() au Signs InsertLeave * call Highlight_Signs() endif + + au Mode BufEnter \[BufExplorer\] call BufExplorer_Map() endif " Limit the size of the popup menu when completing. -- 2.20.1