4

Suppose I have two files with the following filepaths:

~/another/project/file1.txt
~/this/is/some/very/deep/project/file2.txt

As you could see, file1.txt and file2.txt are located "far way" from each other in the filesystem.

Now suppose I'm editing file1.txt, and I want to open up file2.txt in a vsplit window. The fastest method I'd chose to open up file2.txt is

:vsplit ~/this/is/some/very/deep/project/file2.txt

which is obviously not efficient, even with fuzzy completion.

Is there a way to quickly "bookmark" or "jump to a directory" to reach file2.txt quickly?

My initial thoughts would be to execute a command from the shell (within command mode, using !) to somehow facilitate the jumping. Using something like jump might help, but I wouldn't know how.

3 Answers 3

3

You could try using a global mark, as described in the answer to this question:

https://stackoverflow.com/questions/1581505/vim-create-marks-across-files

If you make a mark with a capital letter like mA, you can return to that file by going to that mark with 'A.

This'll work across sessions if your .viminfo is saving things properly.

1
  • You learn a new vim trick everyday. This seems more preferable than symlinking files. Thanks.
    – hlin117
    Jan 8, 2015 at 2:32
0

If you are using the same files regularly you can use a symbolic link.

Make a folder to keep your links in.

mkdir ~/links/

link your files.

ln ~/another/project/file1.txt ~/links/file1.txt
ln ~/this/is/some/very/deep/project/file2.txt ~/links/file2.txt

You can also name your link differently. If your file is somereallylongname.txt you can link it to shname.txt

ln ~/this/is/some/very/deep/project/somereallylongname.txt ~/links/shname.txt
2
  • I suppose a symbolic link would be a solution. But like you mentioned, I'd make a link if I used the same files regularly; for my use case, I'm hoping to only open up file2.txt once or twice.
    – hlin117
    Jan 8, 2015 at 1:34
  • Fair enough. Do these files usually exist in the same deep directory. you could link the whole directory as well.
    – JpaytonWPD
    Jan 8, 2015 at 13:33
0

Another answer presented to me by a friend was to use the ctrlp plugin. The ctrlp plugin makes it easy to search for a file though multiple directories at the same time.

EDIT: The default settings for ctrlp would actually start searching from the root of the project; technically, one would have to set the root node differently to get it to work properly.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .