On Wed, 10 May 2006 at 8:10am, Benjamin Reitzammer wrote:
> Hi,
>
> thanks a lot, for all your responses. And for being so blazingly fast.
> Just like vim itself ;)
>
> Using a tags file is the closest to the described functionality I was
> looking for. Although I must say that having to press the <tab> key to
> request a completion is not nearly as nice as having a list
> automatically update.
>
> Yakov said, getting something like this in vim would be quite hard, but
> I think, that I might give it a shot nonetheless. You sure will hear
> about it, if I do so.
>
> Thanks again for being so helpful
>
> Cheers
>
> Benjamin
If you go with the tag file approach, it is not that hard to cook up
something quickly, without having to press tab. Here is something very
unpolished, but shows the approach (code copied from my execmap.vim
plugin):
function! LookupFile()
" Open a new buffer to show the results.
new
redraw
" Generate a line with spaces to clear the previous message.
let i = 1
let clearLine = "\r"
while i < &columns
let clearLine = clearLine . ' '
let i = i + 1
endwhile
let str = ""
call Prompt(str)
let breakLoop = 0
let accepted = 0
while !breakLoop
try
let char = getchar()
catch /^Vim:Interrupt$/
let char = "\<Esc>"
endtry
if char == '^\d\+$' || type(char) == 0
let char = nr2char(char)
endif " It is the ascii code.
if char == "\<BS>"
let str = strpart(str, 0, strlen(str) - 1)
elseif char == "\<Esc>"
let breakLoop = 1
elseif char == "\<CR>"
let accepted = 1
let breakLoop = 1
else
let str = str . char
endif
" Show the matches for what is typed so far.
silent! 1,$delete
let _tags = &tags
set tags=/tmp/tags
try
let tags = taglist(str)
finally
let &tags = _tags
endtry
for ta in tags
"Why does this generates syntax errors?
"silent put =ta["filename"]
call append('$', ta["filename"])
endfor
redraw
echon clearLine
call Prompt(str)
endwhile
endfunction
function! Prompt(str)
echon "\rLookup file containg: " . a:str
endfunction
If you call LookupFile(), it brings an empty buffer and prompts you to
enter a string. Entering each character makes the buffer show all the
matching filenames. What you sould do in addition is to:
- Avoid hardcoding the tags file.
- Don't lookup tags for each entered character, but only after a short
delay (this could be tricky). This may not be important thought.
- When user finds the file, make it easy to open it (like pressing O on it,
or even opening the file right-away if there is only one match).
- Use a scratch buffer to show results and reuse one buffer. I have
numerous examples in my all my plugins (selectbuf, breakpts etc.)
- Plugginize it, creating maps etc. to invoke the function. Again, if
you don't have much experience, there are several that you can follow.
You can look at my plugins, I try to follow all the plugin writing
rules that Vim doc lists.
--
HTH,
Hari
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com