We have rather complex file structure and I would like simplify opening file independently where am I in the filesystem at the moment.
Let's say we have a project_folder
and several files in it:
/project_folder/common-prefix/foo.txt
/project_folder/common-prefix/bar.txt
/project_folder/common-prefix/nested/zoo.txt
Usually I change to project_folder/common-prefix
and work from it. Some command and documentation usually expose full relative project path, e.g. common-prefix/bar.txt
In this case I have to manually remove common-prefix
to modify interested file. How can I configure vim so that opening a file it's file name would be processed and known prefixes would be removed/replaced?
$ cd /project_folder/common-prefix/
$ vim foo.txt # this works naturally
$ vim common-prefix/foo.txt # here I want to cut `common-prefix`
$ vim ../common-prefix/foo.txt # probably I want to convert to absolute path, but this is a corner case
I read about includeexpr
, but it seems it olny works for gf
commands, whereas I want something like BufRead
/BufNewFile
I found similar questions:
- Modify the path of a file be opened
- How to edit file name under cursor in Vim/Gvim, when it starts with /cygdrive/ in Windows
And also two plugins, which probably close to the implementation I want:
/root_folder/foo.txt
, that's a valid path after all... Is the issue the path attached to the buffer (when you use:ls
to list buffers, or the path shown in the status line)? Does it help if you:cd
to the directory where the file is inside Vim? Do you want to change the behavior for paths listed in the command-line arguments, or for using the:e
and similar commands inside Vim, or both? Please be more specific about the actual issue you're having, with realistic examples if possible. Thanks!