In Vim, is it possible to open a file in specify opened split window?

Go To StackoverFlow.com

3

Recently, I use Vim as my editor while programming Ruby, but I don't know if I can do that in Vim. Let's say in my Vim, I already have 2 vertical split windows named A and B like this:

split window

And then I hit gf to jump to the source file xyz.rb if I park the cursor under the require statement, but it will show in the same window A by default.

Is there any shortcuts or quick combo that I can open or show the source file xyz.rb in the opened B split window? (and even if the window B doesn't exist yet, create one automatically)

I've check the manual, and it does has some ways to show xyz.rb in different horizontal split window or a new tab, but is it possible if I want to show it in specify opened split window B.

thanks :)

2012-04-05 22:34
by XXX


4

The functionality you describe is already present in the form of a 'preview window'.

You could map a key (e.g. gf) to something like

:exec 'pedit ' . expand('<cfile>')

This will open the filename under the cursor in the preview window. A new preview window will be opened if none exists. See :he preview-window for more information.

Use ^Wz (or :pclose) to close the preview window

2012-04-05 22:43
by sehe
thanks for your reply, but the preview window might be a little different from what I want. first, I need the opened file would be editable, not just preview. and second, I want the file opened in the specify split window which is already exist, like the window B in the above picture. : - XXX 2012-04-05 22:56
@高見龍 in what way? Perhaps I can help you find what you wan - sehe 2012-04-05 22:58
actually, I am not sure is that possible to do that : - XXX 2012-04-05 23:02
Well, I'm sure it isn't possible unless you tell me what you need/what you don't like about the preview windo - sehe 2012-04-05 23:04
Thanks again, my actually need is while I'm editing a source file named A, and sometimes I want to edit the source file B which is required by file A. I used to hit gf to jump to the file and jump back by ctrl+^, but since I have a wide monitor, why not just show the source file B in the right side split window? But sometimes the right side split window already open the other file, just like the attached image above. So, my question is: is there any way to open the file B in some split window which already exist, and not just preview, I might need it to be editable : - XXX 2012-04-05 23:18
sorry I'm not native English, please bear my poor grammar : - XXX 2012-04-05 23:18
actually I can do that with several steps, such as :vs to open a new vertical window if the split window doesn't exist, and then hit gf to show the file. I'm just curious is there any easy way to do that : - XXX 2012-04-05 23:23
@高見龍 Erm, Preview window is editable just fine. You could look at :se splitright with ^Wf. Also the switchbuf option might interest you. Also consider :vert peditsehe 2012-04-05 23:25
I think splitright and ^wf would be my answer, thanks : - XXX 2012-04-05 23:39
Ads