Last active
August 29, 2015 13:57
-
-
Save dahu/9718037 to your computer and use it in GitHub Desktop.
Combine the power of [I and :ilist /pattern/ in Vim
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
function! IList() | |
let term = input("IList: /") | |
if term == '' | |
let term = expand('<cword>') | |
endif | |
let v:errmsg = '' | |
redir =>slist | |
exe 'ilist /' . term | |
redir END | |
if v:errmsg == '' | |
let llist = split(slist, "\n") " remove \@ nuls | |
let slist = join(llist, "\n") | |
call filter(llist, 'v:val =~ "^\\s\\+\\d\\+:"') | |
let choice = str2nr(input('Find: ')) | |
call histdel('input', -1) " remove numeric choice leaving named term as last | |
if (choice > 0) && (choice <= len(llist)) | |
let line = matchstr(llist[choice-1], '^\s*\d\+:\s\+\zs\d\+') | |
let file = split(matchstr(slist, '\_.*\%(\_^\|\n\)\zs\S\+\ze\_.\{-}\n\s\+' . choice))[0] " remove \@ nul | |
if bufexists(file) | |
exe 'buffer ' . file | |
else | |
exe 'edit ' . file | |
endif | |
exe line | |
normal! 0 | |
call search(term, 'c') | |
endif | |
else | |
let v:errmsg .= ': ' . term | |
endif | |
endfunction | |
nnoremap [I :call IList()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment