vim9script: how to find current executing file path

12 views
Skip to first unread message

Ernie Rael

unread,
Jan 28, 2023, 1:09:54 PM1/28/23
to vim...@googlegroups.com
I'm working on a project with several files. I try to mostly work in a
"dev" location where I can run the various files individually; the files
usually have a in_dev flag, which sets things up to run standalone
(often simply adjusting imports). When ready to run in the application,
I copy the file to their "real" location and manually adjust what's
needed in the files. The manual step is a hassle.

If I could get the realpath of the file that's executing I could set the
flags when the file is first loaded (and remember to do "source %" and
not "source" while playing), and not need manual adjustments.

Then I can automate the update of the app files.

-ernie

Ernie Rael

unread,
Jan 28, 2023, 1:52:27 PM1/28/23
to vim...@googlegroups.com
For my use case, I think I can simply use the current directory.

-ernie

Bram Moolenaar

unread,
Jan 29, 2023, 8:34:05 AM1/29/23
to vim...@googlegroups.com, Ernie Rael
It's not clear what files you are working with. If they are Vim script,
you can get the full path of the script with:

echo expand('<sfile>:p')

or:

echo expand('<script>:p')

--
hundred-and-one symptoms of being an internet addict:
61. Your best friends know your e-mail address, but neither your phone number
nor the address where you live.

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ernie Rael

unread,
Jan 29, 2023, 11:27:51 AM1/29/23
to vim...@googlegroups.com
On 23/01/29 5:33 AM, Bram Moolenaar wrote:
> Ernie Rael wrote:
>>
>> If I could get the realpath of the file that's executing
> It's not clear what files you are working with. If they are Vim script,
> you can get the full path of the script with:
>
> echo expand('<sfile>:p')
>
> or:
>
> echo expand('<script>:p')
>
Aha, Thanks.

Even though I worked intensively with vim9script for a few months last year,
I'm still so much a novice in vim... (I spend a lot of time in an IDE).

-ernie

Reply all
Reply to author
Forward
0 new messages