Wednesday, May 30, 2012

Re: Call external command with relative path

On Wed, 30 May 2012, oversky wrote:

> I install gvimPortable in a thumb drive.
> The $VIMRUNTIME is d:\Dropbox\Portable\GVimPortable\App\vim\vim73\.
> I have a character encoding converter located in d:\Dropbox\Portable
> \ConvertZ\ConvertZ.exe
> Currently, I use :%!D:\PROGRA~1\ConvertZ\ConvertZ.exe /i:utf8 /o:big5
> % to run the converter.
> However, when I plug the thumb drive into another computer, the driver
> letter of the thumb drive may change to another one.
> How do I change the absolute path of convertz.exe to a relative path
> referring to $VIMRUNTIME?

You should be able to get the prefix (D:\Dropbox\Portable) by using:

let $PORTABLE = fnamemodify($VIMRUNTIME, ':h:h:h:h')

You might need to change the number of :h's. There may also be fewer
:h's if you use $VIM instead of $VIMRUNTIME.

Then your command can become:

:%!$PORTABLE\ConvertZ\ConvertZ.exe /i:utf8 /o:big5

You may also wish to add ':8' to the modifiers, so that you get a
filename that will never have spaces in it.

See:
:help fnamemodify()
:help filename-modifiers

--
Best,
Ben

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: