I want to open a file in Vim like in Eclipse using Ctrl + Shift + R, or via the Ctrl + N option of autofill. Invoke a
I use a couple of shortcuts in my .vimrc file (exact syntax below).
They are based on the fact that in 90% of the cases, I want to open another file in the same directory as the file that I am currently editing, or in a directory that is very close in the hierarchy to that edited file.
Here's what the commands do do:
,cd
: Change the current working directory to the directory that the current file you are editing is in.
,e
: Opens a file with the current working directory already filled in so you have to specify only the filename.
Put these into your .vimrc:
map ,e :e =expand("%:p:h") . "/"
map ,cd :cd %:p:h
Here's a sequence of events:
,cd
-> Current working directory now
becomes "/home/prog",e
-> Expands to ":e /home/prog" so
that you can just fill in the file
name, say test.h.,e
-> Expands to ":e /home"tab
-> Cycle through subdirectories of /homeenter
-> cd
to the directory you
want say /home/prog,e
-> Expands to ":e /home/prog"