Home » Questions » Computers [ Ask a new question ]

How do I open the directory of the current open file?

How do I open the directory of the current open file?

If I open a file with vim dir/to/my/file.c how can I easily open the directory dir/to/my in vim's filebrowser?

Asked by: Guest | Views: 368
Total answers/comments: 5
bert [Entry]

"Try :Ex[plore]. From :help Ex:

:Explore will open the
local-directory browser on the current
file's
directory (or on directory [dir] if specified). The window will
be
split only if the file has been modified, otherwise the browsing
window will take over that window. Normally the splitting is
taken
horizontally."
bert [Entry]

"You could use:

:e %:h

More info on expansions is here: http://vimdoc.sourceforge.net/htmldoc/eval.html#expand()"
bert [Entry]

":e `dirname %`

dirname expands to the directory in which current file is."
":e `dirname %`

dirname expands to the directory in which current file is."
bert [Entry]

":e dir/to/my/

:e . opens the directory you initially launched vim from.

Vim browser 'c' sets the working directory.

I'm not sure if there is a way to automatically jump to the directory of the file you are editing."
bert [Entry]

"If you edit with the pwd command on unix it will open the current directory you are in.

:e `pwd`

This will not work like you want it if you did a cd while in vim."