In vim, when I have a buffer open, I often need to load another file in the same directory that file is in, but since I don't usually cd
into it, the pwd
is a parent folder, so I have to retype the path every time. Is there a shortcut for this? or a way to change the pwd to the directory the file is in?
example:
cd /src
vi lib/foo/file.js
lib/foo has two files: file.js
and file2.js
in vi:
:e file2.js # doesn't work
Add this line to your
vimrc
configuration% current file name
:p expand to full path
:h head (last path component removed)
See
:help expand
for further information.Try the following:
I have the following three lines on my
.vimrc
:Now
,e <some-file>
opens on this buffer.,t
and,s
do the same but on a new tab/split window.Another option is to do:
This cycles through folders in your working directory.
Newer versions of vim have a autochdir command built in, if not you can fall back to a BufEnter like setup.
:Ex short for :Explore does exactly what you asked for.