Wednesday, January 27, 2010

Re: Vim script, not show path.

Hi,

Athunye wrote:
> I have this little script:
> function! VS()
> let mypath = '~/public_html/jeditux.home/vim_sessions/'
> let ans = input('Session name: ', mypath, 'file')
> execute ':source ' ans
> endfunction
>
> http://vim.pastey.net/132026
>
> In the line 'let ans = input ... ... ' I had to include the path
> because otherwise the script would attempt
> to complete filenames from the current dir I am, not the dir with the
> vim saved sessions.
>
> I need a way to make the script not show the path when asking for
> 'Session name', just to make it more
> clear for when I'm typing the file name.
>
> Any help would be appreciated. Thanks in advance.

you can define your own custom completion function which can take care of
removing the paths, e.g.:

let s:CompletionPath = ''

function! CompleteFromPath(ArgLead, CmdLine, CursorPos)
let files = split(glob(s:CompletionPath . '*'), "\n")
call map(files, 'substitute(v:val, ".*/", "", "")')
return join(files, "\n")
endfunction

function! VS()
let s:CompletionPath = '~/public_html/jeditux.home/vim_sessions/'
let ans = input('Session name: ', '', 'custom,CompleteFromPath')
execute ':source ' . s:CompletionPath . ans
endfunction

Regards,
Jürgen

--
Sometimes I think the surest sign that intelligent life exists elsewhere
in the universe is that none of it has tried to contact us. (Calvin)

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

No comments: