Skip to content

Instantly share code, notes, and snippets.

@chemzqm
Last active December 18, 2015 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chemzqm/75b510b1b1ebe2e086d3 to your computer and use it in GitHub Desktop.
Save chemzqm/75b510b1b1ebe2e086d3 to your computer and use it in GitHub Desktop.
" Jump previous/next according to existence of unite, quickfix list, location list
" make sure only one list is opening
function! s:Filter(name)
return a:name =~# '\v\[(Location List|Quickfix List)\]'
endfunction
function! s:GetBuffer()
redir =>buflist
silent! ls
redir END
let res = filter(split(buflist, '\n'), 's:Filter(v:val)')
if !len(res) | return '' | endif
return res[0]
endfunction
function! s:hasUnite()
for i in range(1, winnr('$'))
let name = bufname(winbufnr(i))
if match(name, '^\[unite\]') == 0
return 1
endif
endfor
endfunction
function! s:Jump(count, direction)
let pre = ''
if s:hasUnite()
let dir = substitute(a:direction, '^\(\a\)', '\U\1', '')
execute a:count . 'Unite' . dir
return
endif
let name = s:GetBuffer()
if !len(name)
echohl WarningMsg | echon 'no list' | echohl None
return
endif
if name =~? 'quickfix'
let cmd = a:count . 'c' . a:direction
elseif name =~? 'location'
let cmd = a:count . 'l' . a:direction
else
echom 'should not happen'
return
endif
try
execute cmd
catch /E553/
echohl WarningMsg | echon 'no more item' | echohl None
endtry
endfunction
nmap <silent> <leader>p :call <SID>Jump(v:count1, 'previous')<cr>
nmap <silent> <leader>n :call <SID>Jump(v:count1, 'next')<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment