-
-
Save kshenoy/9719524 to your computer and use it in GitHub Desktop.
An unholy amalgam of [I and :ilist. This function allows to specify a pattern and then displays all lines matching that pattern and also jumps to one of the lines
This file contains 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! IListpp() | |
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 :<C-U>call IListpp()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment