[EMAIL PROTECTED] wrote:
What is the easiest way to edit a file that is in the same directory as
the current file? E.g. I open a file like this: vim /x/y/z/w/file1.c and
want to now open /x/y/z/w/file2.c? Occasionally want to open files in
the parent directory of current file's directory. It would be nice if
there is a special character like "," which starts from the current
buffer's directory. So ":e ,/file2.c" would work. Or maybe "~~" double
tilda character if "," doesn't work...

Thanks, Malahal.



Method 1: One particular file

        :e %:h/filename

Method 2: Change directory for the current window only (assuming other files, possibly in other directories, are in split windows which are not to be affected)

        :lcd %:h
        :e file1
        " do some edits
        :w
        :e file2
        " etc.

Method 3: Change the "current directory" for the whole of Vim

        :cd %:h
        :e file1
        " do something
        :w
        :e file2
        " etc.

In all the above examples, you can use ":new" ":tabnew" etc. instead of ":e". In Method 2 the "child" window will (IIUC) inherit the ":lcd" setting of its "parent", i.e. of the one which was current when you issued the "new" (etc.) command.

See
        :help :cd
        :help :_%
        :help filename-modifiers
        :help :lcd
        " etc.


HTH,
Tony.

Reply via email to