Okay, here's a couple of versions depending upon which version of vim you have. I don't know if it's universal, but my installation of version 6.3 has a non-functioning getcmdline command, and vim7 adds a useful new command, getcmdtype, hence:
" Get path to current file in command-line using comma if v:version >= 700 " Use getcmdtype, new to 700, but disallow on "set" and "let" cnoremap , <c-r>=getcmdtype()==':'&&match(getcmdline(),'\v(^\| )(se\|set\|let) ')==-1?expand('%:h').'/':','<cr> elseif v:version > 603 " No getcmdtype function, allow on e/sp/vsp commands only, vert sp should also work cnoremap , <c-r>=match(getcmdline(),'\v^(vert \|)(e\|v?sp) ')!=-1?expand('%:h').'/':','<cr> else " Seems to be a bug in getcmdline in my vim 6.3 - use the simple method cnoremap , <c-r>=expand('%:h')<cr>/ endif Hope the email program doesn't bugger that up too much, and as always, customise it for your needs. Cheers, John On Thursday 20 July 2006 11:50, John Orr wrote: > On Thursday 20 July 2006 11:10, [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... > > A while back I defined the mapping > cmap , <c-r>=expand('%:h')<cr>/ > which kind of does what you suggested - it inserts the path to the current > file when you type a comma in the command line. I've found it very useful. > For what I'm doing at present, it suits me to have it. But it does mean that > when I want a real comma (eg in a search pattern, or a :set command) I have > to use Ctrl-v or Ctrl-q first. > I guess it could easily be improved call a function which checks the command > line to see if it starts with > :e, :sp, and whatever else is appropriate - and otherwise inserts a regular > comma. I'll let you know if I get around to it. > > John >