# HG changeset patch # User Ludovic Chabant # Date 1601014387 25200 # Node ID b452486b97c5a559bc88dfe278bb1e49c113bb5d # Parent 25bdfc963612f573597b0afa9c0a4421d66f01ed Make vim's quickfix list more awesome. diff -r 25bdfc963612 -r b452486b97c5 vim/autoload/quickfixed.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vim/autoload/quickfixed.vim Thu Sep 24 23:13:07 2020 -0700 @@ -0,0 +1,71 @@ +" Stolen from https://vimways.org/2018/colder-quickfix-lists/ +" ~/.vim/autoload/quickfixed.vim +function! s:isLocation() + " Get dictionary of properties of the current window + let wininfo = filter(getwininfo(), {i,v -> v.winnr == winnr()})[0] + return wininfo.loclist +endfunction + +function! s:length() + " Get the size of the current quickfix/location list + return len(s:isLocation() ? getloclist(0) : getqflist()) +endfunction + +function! s:getProperty(key, ...) + " getqflist() and getloclist() expect a dictionary argument + " If a 2nd argument has been passed in, use it as the value, else 0 + let l:what = {a:key : a:0 ? a:1 : 0} + let l:listdict = s:isLocation() ? getloclist(0, l:what) : getqflist(l:what) + return get(l:listdict, a:key) +endfunction + +function! s:isFirst() + return s:getProperty('nr') <= 1 +endfunction + +function! s:isLast() + return s:getProperty('nr') == s:getProperty('nr', '$') +endfunction + +function! s:history(goNewer) + " Build the command: one of colder/cnewer/lolder/lnewer + let l:cmd = (s:isLocation() ? 'l' : 'c') . (a:goNewer ? 'newer' : 'older') + + " Apply the cmd repeatedly until we hit a non-empty list, or first/last list + " is reached + while 1 + if (a:goNewer && s:isLast()) || (!a:goNewer && s:isFirst()) | break | endif + " Run the command. Use :silent to suppress message-history output. + " Note that the :try wrapper is no longer necessary + silent execute l:cmd + if s:length() | break | endif + endwhile + + " Set the height of the quickfix window to the size of the list, max-height 10 + execute 'resize' min([ 10, max([ 1, s:length() ]) ]) + + " Echo a description of the new quickfix / location list. + " And make it look like a rainbow. + let l:nr = s:getProperty('nr') + let l:last = s:getProperty('nr', '$') + echohl MoreMsg | echon '(' + echohl Identifier | echon l:nr + if l:last > 1 + echohl LineNr | echon ' of ' + echohl Identifier | echon l:last + endif + echohl MoreMsg | echon ') ' + echohl MoreMsg | echon '[' + echohl Identifier | echon s:length() + echohl MoreMsg | echon '] ' + echohl Normal | echon s:getProperty('title') + echohl None +endfunction + +function! quickfixed#older() + call s:history(0) +endfunction + +function! quickfixed#newer() + call s:history(1) +endfunction diff -r 25bdfc963612 -r b452486b97c5 vim/ftplugin/qf.vim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vim/ftplugin/qf.vim Thu Sep 24 23:13:07 2020 -0700 @@ -0,0 +1,4 @@ +" Stolen from https://vimways.org/2018/colder-quickfix-lists/ +" Use so ":call quickfixed#older()" isn't output to the command line +nnoremap :call quickfixed#older() +nnoremap :call quickfixed#newer() diff -r 25bdfc963612 -r b452486b97c5 vim/vimrc --- a/vim/vimrc Thu Sep 24 23:11:23 2020 -0700 +++ b/vim/vimrc Thu Sep 24 23:13:07 2020 -0700 @@ -701,6 +701,9 @@ nnoremap ]l :lnextzvzz nnoremap [l :lpreviouszvzz +" Toggle quicklist. +nnoremap :call ludo#toggle_quicklist() + " Same with change and jump lists. nnoremap ]e g,zz nnoremap [e g;zz