Wednesday, January 27, 2010

Re: Vim script, not show path.

On Wed, Jan 27, at 03:28 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.

I saw you already took an extensive answer from Jürgen, but you could make
your own function to work, by simple using "cd", to change directory and
then let vim do the rest, without using extra functions.

To make your function a little bit more robust, you can use a try/catch
to see if vim can change to that directory, or you can use for the same
purpose the isdirectory() vim function to see if the directory actual
exists, so you can gracefully handle an error, like:

function! VS()
try
cd ~/public_html/jeditux.home/vim_sessions/
catch /^Vim\%((\a\+)\)\=:E344/
echo "Caught an exception\nVIM EXCEPTION: ".v:exception
return 1
endtry
let ans = input('Session name: ', '', 'file')
execute ':source '.ans
endfunction

Regards,
Agathoklis.

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

No comments: