Friday, April 17, 2020

Re: How to get directory of current file.

On 2020-04-17, DwigtArmyOfChampions wrote:
> I am using gVim on Windows. I open a file in C:\tmp called
> file1.cpp. After looking around in file1.cpp I now want to open
> file2.cpp which is also in C:\tmp. So I run the command
>
> :e .\file2.cpp
>
> But this doesn't work because the "." is C:\Windows\system32. Is
> there a different character or function or variable I can use in
> command mode to designate "the directory that the current file is
> in"?

One way:

:e %:h/file2.cpp

%:h will expand to the parent directory of the current file.

Another way:

:e ^R%

where ^R is Ctrl-R, will put the current file name on the command
line where you can edit it to the file name you want.

See

:help filename-modifiers
:help c_CTRL-R

Regards,
Gary

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/20200417152247.GA22179%40phoenix.

No comments: