Tuesday, January 26, 2010

Re: lookforward during filename completion

On Tue, January 26, 2010 5:28 pm, Tim Chase wrote:
> Unless you have a filename like "foo.tar.gz" in which case you
> have to remember to do ^W 2x :) It would certainly be nice to
> have Vim do the "right" thing. or perhaps have an "inner
> file-name without path" text object but that would be asking a lot :)

Oh well, only barely tested:

,----
| fu! <sid>MyFileNameCompletion(f,b)
| if a:f
| let line = getline('.')
| let start = col('.') - 1
| while start > 0 && line[start - 1] =~ '\f'
| let start -= 1
| endwhile
| return start
| else
| let line = getline('.')
| let end = col('.')-1
| let start = col('.')-1
| while end > 1 && line[end+1] =~ '\f'
| let end += 1
| endw
| let suffix=getline('.')[start : end]
| let list=split(glob(a:b."*"), '\n')
| call map(list, "matchstr(v:val, '.*\\ze'.suffix)")
| return list
| endif
| endfu
|
| set cfu=MyFileNameCompletion
|
| inoremap <C-X><C-F> <C-X><C-U>
`----

regards,
Christian

--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment