System Administration
cancel
Showing results for 
Search instead for 
Did you mean: 

How to open a file in a different directory using vi

Sirisha_1
Occasional Visitor

How to open a file in a different directory using vi

I would like to know if there is any way to open a file that is in some different directory , without giving the absolute path name . I mean , just by giving the name of the file to vi .Is there any way to achieve this by manipulating the path variable or using vi with any option .
2 REPLIES
Mark Grant
Honored Contributor

Re: How to open a file in a different directory using vi

No, there isn't but there are ways you could make it look like that.

symbolic or hard link from the file to your current directory is one way.

alias "vmyfile=vi /long/path/to/myfile" so that when you type vmyfile it edits it.

MYFILE=/really/long/path/top/myfile
vi $MYFILE

Maybe this will help.
Never preceed any demonstration with anything more predictive than "watch this"
Romildo
Occasional Visitor

Re: How to open a file in a different directory using vi

Try to use a script that do the following ...

#!/usr/bin/ksh
file=$(which $1)
vi $file

the script would be call vi.sh and you use vi.sh file.

good luck.

Romildo