Last active
December 18, 2015 03:38
-
-
Save chemzqm/75b510b1b1ebe2e086d3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" 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